1 ###############################################################################
3 # Package: NaturalDocs::ImageReferenceTable::String
5 ###############################################################################
7 # A package for creating and managing <ImageReferenceStrings>.
9 ###############################################################################
11 # This file is part of Natural Docs, which is Copyright © 2003-2010 Greg Valure
12 # Natural Docs is licensed under version 3 of the GNU Affero General Public License (AGPL)
13 # Refer to License.txt for the complete details
19 package NaturalDocs::ImageReferenceTable::String;
23 # Type: ImageReferenceString
25 # A string representing a unique image reference. It's composed of the reference text and the directory of the source file.
26 # The source file name itself isn't included because two files in the same directory with the same reference text will always go
27 # to the same targets.
34 # Converts a source <FileName> and the reference text to an <ImageReferenceString>.
36 sub Make #(FileName sourceFile, string text) => ImageReferenceString
38 my ($self, $sourceFile, $text) = @_;
40 my $path = NaturalDocs::File->NoFileName($sourceFile);
42 # Condense whitespace and remove any separator characters.
43 $path =~ tr/ \t\r\n\x1C/ /s;
44 $text =~ tr/ \t\r\n\x1C/ /s;
46 return $path . "\x1C" . $text;
51 # Function: InformationOf
53 # Returns the information contained in the <ImageReferenceString> as the array ( path, text ).
55 sub InformationOf #(ImageReferenceString referenceString)
57 my ($self, $referenceString) = @_;
58 return split(/\x1C/, $referenceString);
63 # Function: ToBinaryFile
65 # Writes an <ImageReferenceString> to <NaturalDocs::BinaryFile>. Can also encode an undef.
69 # > [UString16: path] [UString16: reference text] ...
71 # Undef is represented by the first UString16 being undef.
73 sub ToBinaryFile #(ImageReferenceString referenceString)
75 my ($self, $referenceString) = @_;
77 if (defined $referenceString)
79 my ($path, $text) = split(/\x1C/, $referenceString);
81 NaturalDocs::BinaryFile->WriteUString16($path);
82 NaturalDocs::BinaryFile->WriteUString16($text);
86 NaturalDocs::BinaryFile->WriteUString16(undef);
92 # Function: FromBinaryFile
94 # Loads an <ImageReferenceString> or undef from <NaturalDocs::BinaryFile> and returns it.
100 my $path = NaturalDocs::BinaryFile->GetUString16();
105 my $text = NaturalDocs::BinaryFile->GetUString16();
107 return $path . "\x1C" . $text;