using System;
using System.Collections.Generic;
using System.Text;
namespace ScrewTurn.Wiki.PluginFramework {
///
/// Implements useful tools for handling full object names.
///
public static class NameTools {
///
/// Gets the full name of a page from the namespace and local name.
///
/// The namespace (null for the root).
/// The local name.
/// The full name.
public static string GetFullName(string nspace, string name) {
return (!string.IsNullOrEmpty(nspace) ? nspace + "." : "") + name;
}
///
/// Expands a full name into the namespace and local name.
///
/// The full name to expand.
/// The namespace.
/// The local name.
public static void ExpandFullName(string fullName, out string nspace, out string name) {
if(fullName == null) {
nspace = null;
name = null;
}
else {
string[] fields = fullName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
if(fields.Length == 0) {
nspace = null;
name = null;
}
else if(fields.Length == 1) {
nspace = null;
name = fields[0];
}
else {
nspace = fields[0];
name = fields[1];
}
}
}
///
/// Extracts the namespace from a full name.
///
/// The full name.
/// The namespace, or null.
public static string GetNamespace(string fullName) {
string nspace, name;
ExpandFullName(fullName, out nspace, out name);
return nspace;
}
///
/// Extracts the local name from a full name.
///
/// The full name.
/// The local name.
public static string GetLocalName(string fullName) {
string nspace, name;
ExpandFullName(fullName, out nspace, out name);
return name;
}
}
}