1
#region PDFsharp - A .NET library for processing PDF
4
// Stefan Lange (mailto:Stefan.Lange@pdfsharp.com)
6
// Copyright (c) 2005-2008 empira Software GmbH, Cologne (Germany)
8
// http://www.pdfsharp.com
9
// http://sourceforge.net/projects/pdfsharp
11
// Permission is hereby granted, free of charge, to any person obtaining a
12
// copy of this software and associated documentation files (the "Software"),
13
// to deal in the Software without restriction, including without limitation
14
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
// and/or sell copies of the Software, and to permit persons to whom the
16
// Software is furnished to do so, subject to the following conditions:
18
// The above copyright notice and this permission notice shall be included
19
// in all copies or substantial portions of the Software.
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
// DEALINGS IN THE SOFTWARE.
31
using System.Diagnostics;
32
using System.Collections;
35
using PdfSharp.Internal;
36
using PdfSharp.Pdf.IO;
38
namespace PdfSharp.Pdf
41
/// Represents a PDF name value.
43
[DebuggerDisplay("({Value})")]
44
public sealed class PdfName : PdfItem
47
/// Initializes a new instance of the <see cref="PdfName"/> class.
51
this.value = "/"; // Empty name.
55
/// Initializes a new instance of the <see cref="PdfName"/> class.
57
public PdfName(string value)
60
throw new ArgumentNullException("value");
61
if (value.Length == 0 || value[0] != '/')
62
throw new ArgumentException(PSSR.NameMustStartWithSlash);
68
/// Determines whether the specified object is equal to this name.
70
public override bool Equals(object obj)
72
return this.value.Equals(obj);
76
/// Returns the hash code for this instance.
78
public override int GetHashCode()
80
return this.value.GetHashCode();
84
/// Gets the name as a string.
88
// This class must behave like a value type. Therefore it cannot be changed (like System.String).
89
get { return this.value; }
94
/// Returns the name. The string always begins with a slash.
96
public override string ToString()
102
/// Determines whether the specified name and string are equal.
104
public static bool operator ==(PdfName name, string str)
106
return name.value == str;
110
/// Determines whether the specified name and string are not equal.
112
public static bool operator !=(PdfName name, string str)
114
return name.value != str;
117
#if leads_to_ambiguity
118
public static bool operator ==(string str, PdfName name)
120
return str == name.value;
123
public static bool operator !=(string str, PdfName name)
125
return str == name.value;
128
public static bool operator ==(PdfName name1, PdfName name2)
130
return name1.value == name2.value;
133
public static bool operator !=(PdfName name1, PdfName name2)
135
return name1.value != name2.value;
140
/// Represents the empty name.
142
public static readonly PdfName Empty = new PdfName("/");
145
/// Writes the name including the leading slash.
147
internal override void WriteObject(PdfWriter writer)
149
// TODO: what if unicode character are part of the name?
154
/// Gets the comparer for this type.
156
public static PdfXNameComparer Comparer
158
get { return new PdfXNameComparer(); }
162
/// Implements a comparer that compares PdfName objects.
164
public class PdfXNameComparer : IComparer
167
/// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
169
/// <param name="x">The first object to compare.</param>
170
/// <param name="y">The second object to compare.</param>
171
public int Compare(object x, object y)
173
PdfName l = x as PdfName;
174
PdfName r = y as PdfName;
178
return l.value.CompareTo(r.value);