~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.XmlEditor/MonoDevelop.XmlEditor/XmlNamespace.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// MonoDevelop XML Editor
 
3
//
 
4
// Copyright (C) 2006 Matthew Ward
 
5
//
 
6
 
 
7
using System;
 
8
 
 
9
namespace MonoDevelop.XmlEditor
 
10
{
 
11
        /// <summary>
 
12
        /// A namespace Uri and a prefix.
 
13
        /// </summary>
 
14
        public class XmlNamespace
 
15
        {
 
16
                string prefix = String.Empty;
 
17
                string uri = String.Empty;
 
18
                
 
19
                const string prefixToStringStart = "Prefix [";
 
20
                const string uriToStringMiddle = "] Uri [";
 
21
                
 
22
                public XmlNamespace(string prefix, string uri)
 
23
                {
 
24
                        this.prefix = prefix;
 
25
                        this.uri = uri;
 
26
                }
 
27
                
 
28
                public string Prefix {
 
29
                        get {
 
30
                                return prefix;
 
31
                        }
 
32
                }
 
33
                
 
34
                public string Uri {
 
35
                        get {
 
36
                                return uri;
 
37
                        }
 
38
                }
 
39
                
 
40
                public override string ToString()
 
41
                {
 
42
                        return String.Concat(prefixToStringStart, prefix, uriToStringMiddle, uri, "]");
 
43
                }
 
44
                
 
45
                /// <summary>
 
46
                /// Creates an XmlNamespace instance from the given string that is in the
 
47
                /// format returned by ToString.
 
48
                /// </summary>
 
49
                public static XmlNamespace FromString(string s)
 
50
                {
 
51
                        int prefixIndex = s.IndexOf(prefixToStringStart);
 
52
                        if (prefixIndex >= 0) {
 
53
                                prefixIndex += prefixToStringStart.Length;
 
54
                                int uriIndex = s.IndexOf(uriToStringMiddle, prefixIndex);
 
55
                                if (uriIndex >= 0) {
 
56
                                        string prefix = s.Substring(prefixIndex, uriIndex - prefixIndex);
 
57
                                        uriIndex += uriToStringMiddle.Length;
 
58
                                        string uri = s.Substring(uriIndex, s.Length - (uriIndex + 1));
 
59
                                        return new XmlNamespace(prefix, uri);
 
60
                                }
 
61
                        }
 
62
                        return new XmlNamespace(String.Empty, String.Empty);
 
63
                }
 
64
        }
 
65
}