OSDN Git Service

Version 5.91
[vbslib/main.git] / GPL_bin_fullset / NaturalDocs / Modules / NaturalDocs / ImageReferenceTable / String.pm
1 ###############################################################################
2 #
3 #   Package: NaturalDocs::ImageReferenceTable::String
4 #
5 ###############################################################################
6 #
7 #   A package for creating and managing <ImageReferenceStrings>.
8 #
9 ###############################################################################
10
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
14
15 use strict;
16 use integer;
17
18
19 package NaturalDocs::ImageReferenceTable::String;
20
21
22 #
23 #   Type: ImageReferenceString
24 #
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.
28 #
29
30
31 #
32 #   Function: Make
33 #
34 #   Converts a source <FileName> and the reference text to an <ImageReferenceString>.
35 #
36 sub Make #(FileName sourceFile, string text) => ImageReferenceString
37     {
38     my ($self, $sourceFile, $text) = @_;
39
40     my $path = NaturalDocs::File->NoFileName($sourceFile);
41
42     # Condense whitespace and remove any separator characters.
43     $path =~ tr/ \t\r\n\x1C/ /s;
44     $text =~ tr/ \t\r\n\x1C/ /s;
45
46     return $path . "\x1C" . $text;
47     };
48
49
50 #
51 #   Function: InformationOf
52 #
53 #   Returns the information contained in the <ImageReferenceString> as the array ( path, text ).
54 #
55 sub InformationOf #(ImageReferenceString referenceString)
56     {
57     my ($self, $referenceString) = @_;
58     return split(/\x1C/, $referenceString);
59     };
60
61
62 #
63 #   Function: ToBinaryFile
64 #
65 #   Writes an <ImageReferenceString> to <NaturalDocs::BinaryFile>.  Can also encode an undef.
66 #
67 #   Format:
68 #
69 #       > [UString16: path] [UString16: reference text] ...
70 #
71 #       Undef is represented by the first UString16 being undef.
72 #
73 sub ToBinaryFile #(ImageReferenceString referenceString)
74     {
75     my ($self, $referenceString) = @_;
76
77     if (defined $referenceString)
78         {
79         my ($path, $text) = split(/\x1C/, $referenceString);
80
81         NaturalDocs::BinaryFile->WriteUString16($path);
82         NaturalDocs::BinaryFile->WriteUString16($text);
83         }
84     else
85         {
86         NaturalDocs::BinaryFile->WriteUString16(undef);
87         };
88     };
89
90
91 #
92 #   Function: FromBinaryFile
93 #
94 #   Loads an <ImageReferenceString> or undef from <NaturalDocs::BinaryFile> and returns it.
95 #
96 sub FromBinaryFile
97     {
98     my $self = shift;
99
100     my $path = NaturalDocs::BinaryFile->GetUString16();
101
102     if (!defined $path)
103         {  return undef;  };
104
105     my $text = NaturalDocs::BinaryFile->GetUString16();
106
107     return $path . "\x1C" . $text;
108     };
109
110
111 1;