blob: 982e9f13163ed8024885898db05d9545ab639a30 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
###############################################################################
#
# Package: NaturalDocs::ImageReferenceTable::String
#
###############################################################################
#
# A package for creating and managing <ImageReferenceStrings>.
#
###############################################################################
# This file is part of Natural Docs, which is Copyright (C) 2003-2008 Greg Valure
# Natural Docs is licensed under the GPL
use strict;
use integer;
package NaturalDocs::ImageReferenceTable::String;
#
# Type: ImageReferenceString
#
# A string representing a unique image reference. It's composed of the reference text and the directory of the source file.
# The source file name itself isn't included because two files in the same directory with the same reference text will always go
# to the same targets.
#
#
# Function: Make
#
# Converts a source <FileName> and the reference text to an <ImageReferenceString>.
#
sub Make #(FileName sourceFile, string text) => ImageReferenceString
{
my ($self, $sourceFile, $text) = @_;
my $path = NaturalDocs::File->NoFileName($sourceFile);
# Condense whitespace and remove any separator characters.
$path =~ tr/ \t\r\n\x1C/ /s;
$text =~ tr/ \t\r\n\x1C/ /s;
return $path . "\x1C" . $text;
};
#
# Function: InformationOf
#
# Returns the information contained in the <ImageReferenceString> as the array ( path, text ).
#
sub InformationOf #(ImageReferenceString referenceString)
{
my ($self, $referenceString) = @_;
return split(/\x1C/, $referenceString);
};
#
# Function: ToBinaryFile
#
# Writes an <ImageReferenceString> to <NaturalDocs::BinaryFile>. Can also encode an undef.
#
# Format:
#
# > [AString16: path] [AString16: reference text] ...
#
# Undef is represented by the first AString16 being undef.
#
sub ToBinaryFile #(ImageReferenceString referenceString)
{
my ($self, $referenceString) = @_;
if (defined $referenceString)
{
my ($path, $text) = split(/\x1C/, $referenceString);
NaturalDocs::BinaryFile->WriteAString16($path);
NaturalDocs::BinaryFile->WriteAString16($text);
}
else
{
NaturalDocs::BinaryFile->WriteAString16(undef);
};
};
#
# Function: FromBinaryFile
#
# Loads an <ImageReferenceString> or undef from <NaturalDocs::BinaryFile> and returns it.
#
sub FromBinaryFile
{
my $self = shift;
my $path = NaturalDocs::BinaryFile->GetAString16();
if (!defined $path)
{ return undef; };
my $text = NaturalDocs::BinaryFile->GetAString16();
return $path . "\x1C" . $text;
};
1;
|