as3corelib 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. data/Gemfile +5 -0
  2. data/Gemfile.lock +28 -0
  3. data/README.textile +79 -0
  4. data/Rakefile +3 -0
  5. data/as3corelib.gemspec +23 -0
  6. data/build/build.properties +48 -0
  7. data/build/build.xml +104 -0
  8. data/examples/JSONExample/JSONExample.mxml +73 -0
  9. data/lib/as3corelib.rb +15 -0
  10. data/src/com/adobe/air/crypto/EncryptionKeyGenerator.as +313 -0
  11. data/src/com/adobe/air/filesystem/FileMonitor.as +245 -0
  12. data/src/com/adobe/air/filesystem/FileUtil.as +63 -0
  13. data/src/com/adobe/air/filesystem/VolumeMonitor.as +184 -0
  14. data/src/com/adobe/air/filesystem/events/FileMonitorEvent.as +61 -0
  15. data/src/com/adobe/air/logging/FileTarget.as +95 -0
  16. data/src/com/adobe/air/net/ResourceCache.as +165 -0
  17. data/src/com/adobe/air/net/events/ResourceCacheEvent.as +70 -0
  18. data/src/com/adobe/crypto/HMAC.as +127 -0
  19. data/src/com/adobe/crypto/MD5.as +281 -0
  20. data/src/com/adobe/crypto/MD5Stream.as +402 -0
  21. data/src/com/adobe/crypto/SHA1.as +289 -0
  22. data/src/com/adobe/crypto/SHA224.as +257 -0
  23. data/src/com/adobe/crypto/SHA256.as +261 -0
  24. data/src/com/adobe/crypto/WSSEUsernameToken.as +114 -0
  25. data/src/com/adobe/errors/IllegalStateError.as +63 -0
  26. data/src/com/adobe/fileformats/vcard/Address.as +47 -0
  27. data/src/com/adobe/fileformats/vcard/Email.as +39 -0
  28. data/src/com/adobe/fileformats/vcard/Phone.as +39 -0
  29. data/src/com/adobe/fileformats/vcard/VCard.as +54 -0
  30. data/src/com/adobe/fileformats/vcard/VCardParser.as +246 -0
  31. data/src/com/adobe/images/BitString.as +39 -0
  32. data/src/com/adobe/images/JPGEncoder.as +648 -0
  33. data/src/com/adobe/images/PNGEncoder.as +141 -0
  34. data/src/com/adobe/net/DynamicURLLoader.as +55 -0
  35. data/src/com/adobe/net/IURIResolver.as +76 -0
  36. data/src/com/adobe/net/MimeTypeMap.as +200 -0
  37. data/src/com/adobe/net/URI.as +2466 -0
  38. data/src/com/adobe/net/URIEncodingBitmap.as +139 -0
  39. data/src/com/adobe/net/proxies/RFC2817Socket.as +198 -0
  40. data/src/com/adobe/protocols/dict/Database.as +66 -0
  41. data/src/com/adobe/protocols/dict/Definition.as +71 -0
  42. data/src/com/adobe/protocols/dict/Dict.as +360 -0
  43. data/src/com/adobe/protocols/dict/DictionaryServer.as +60 -0
  44. data/src/com/adobe/protocols/dict/MatchStrategy.as +66 -0
  45. data/src/com/adobe/protocols/dict/Response.as +71 -0
  46. data/src/com/adobe/protocols/dict/events/ConnectedEvent.as +53 -0
  47. data/src/com/adobe/protocols/dict/events/DatabaseEvent.as +67 -0
  48. data/src/com/adobe/protocols/dict/events/DefinitionEvent.as +70 -0
  49. data/src/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as +69 -0
  50. data/src/com/adobe/protocols/dict/events/DictionaryServerEvent.as +69 -0
  51. data/src/com/adobe/protocols/dict/events/DisconnectedEvent.as +55 -0
  52. data/src/com/adobe/protocols/dict/events/ErrorEvent.as +80 -0
  53. data/src/com/adobe/protocols/dict/events/MatchEvent.as +67 -0
  54. data/src/com/adobe/protocols/dict/events/MatchStrategiesEvent.as +70 -0
  55. data/src/com/adobe/protocols/dict/events/NoMatchEvent.as +54 -0
  56. data/src/com/adobe/protocols/dict/util/CompleteResponseEvent.as +68 -0
  57. data/src/com/adobe/protocols/dict/util/SocketHelper.as +81 -0
  58. data/src/com/adobe/serialization/json/JSON.as +86 -0
  59. data/src/com/adobe/serialization/json/JSONDecoder.as +327 -0
  60. data/src/com/adobe/serialization/json/JSONEncoder.as +312 -0
  61. data/src/com/adobe/serialization/json/JSONParseError.as +87 -0
  62. data/src/com/adobe/serialization/json/JSONToken.as +104 -0
  63. data/src/com/adobe/serialization/json/JSONTokenType.as +69 -0
  64. data/src/com/adobe/serialization/json/JSONTokenizer.as +702 -0
  65. data/src/com/adobe/utils/ArrayUtil.as +187 -0
  66. data/src/com/adobe/utils/DateUtil.as +701 -0
  67. data/src/com/adobe/utils/DictionaryUtil.as +87 -0
  68. data/src/com/adobe/utils/IntUtil.as +99 -0
  69. data/src/com/adobe/utils/NumberFormatter.as +74 -0
  70. data/src/com/adobe/utils/StringUtil.as +239 -0
  71. data/src/com/adobe/utils/XMLUtil.as +168 -0
  72. data/src/com/adobe/webapis/ServiceBase.as +48 -0
  73. data/src/com/adobe/webapis/URLLoaderBase.as +108 -0
  74. data/src/com/adobe/webapis/events/ServiceEvent.as +82 -0
  75. data/tests/src/CoreLibTestRunner-app.xml +135 -0
  76. data/tests/src/CoreLibTestRunner.as +138 -0
  77. data/tests/src/CoreLibTestRunner.mxml +46 -0
  78. data/tests/src/com/adobe/air/crypto/EncryptionKeyGeneratorTest.as +176 -0
  79. data/tests/src/com/adobe/air/filesystem/FileMonitorTest.as +63 -0
  80. data/tests/src/com/adobe/air/filesystem/VolumeMonitorTest.as +57 -0
  81. data/tests/src/com/adobe/air/filesystem/events/FileMonitorEventTest.as +59 -0
  82. data/tests/src/com/adobe/air/net/events/ResourceCacheEventTest.as +72 -0
  83. data/tests/src/com/adobe/crypto/HMACMD5Test.as +134 -0
  84. data/tests/src/com/adobe/crypto/HMACSHA1Test.as +138 -0
  85. data/tests/src/com/adobe/crypto/MD5Test.as +82 -0
  86. data/tests/src/com/adobe/crypto/SHA1Test.as +151 -0
  87. data/tests/src/com/adobe/crypto/SHA224Test.as +104 -0
  88. data/tests/src/com/adobe/crypto/SHA256Test.as +116 -0
  89. data/tests/src/com/adobe/crypto/WSSEUsernameTokenTest.as +87 -0
  90. data/tests/src/com/adobe/images/JPGEncoderTest.as +54 -0
  91. data/tests/src/com/adobe/images/PNGEncoderTest.as +54 -0
  92. data/tests/src/com/adobe/net/URITest.as +589 -0
  93. data/tests/src/com/adobe/protocols/events/ConnectedEventTest.as +59 -0
  94. data/tests/src/com/adobe/protocols/events/DatabaseEventTest.as +62 -0
  95. data/tests/src/com/adobe/protocols/events/DefinitionEventTest.as +61 -0
  96. data/tests/src/com/adobe/protocols/events/DefinitionHeaderEventTest.as +61 -0
  97. data/tests/src/com/adobe/protocols/events/DictionaryServerEventTest.as +61 -0
  98. data/tests/src/com/adobe/protocols/events/DisconnectedEventTest.as +59 -0
  99. data/tests/src/com/adobe/protocols/events/ErrorEventTest.as +63 -0
  100. data/tests/src/com/adobe/protocols/events/MatchEventTest.as +61 -0
  101. data/tests/src/com/adobe/protocols/events/MatchStrategiesEventTest.as +61 -0
  102. data/tests/src/com/adobe/protocols/events/NoMatchEventTest.as +58 -0
  103. data/tests/src/com/adobe/protocols/util/CompletedResponseEventTest.as +60 -0
  104. data/tests/src/com/adobe/serialization/json/JSONTest.as +522 -0
  105. data/tests/src/com/adobe/serialization/json/SimpleClass.as +85 -0
  106. data/tests/src/com/adobe/utils/ArrayUtilTest.as +173 -0
  107. data/tests/src/com/adobe/utils/DateUtilTest.as +436 -0
  108. data/tests/src/com/adobe/utils/DictionaryUtilTest.as +93 -0
  109. data/tests/src/com/adobe/utils/IntUtilTest.as +73 -0
  110. data/tests/src/com/adobe/utils/NumberFormatterTest.as +70 -0
  111. data/tests/src/com/adobe/utils/StringUtilTest.as +304 -0
  112. data/tests/src/com/adobe/utils/XMLUtilTest.as +101 -0
  113. data/tests/src/com/adobe/webapis/events/ServiceEventTest.as +66 -0
  114. metadata +196 -0
@@ -0,0 +1,87 @@
1
+ /*
2
+ Copyright (c) 2008, Adobe Systems Incorporated
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are
7
+ met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice,
10
+ this list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright
13
+ notice, this list of conditions and the following disclaimer in the
14
+ documentation and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of Adobe Systems Incorporated nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+ package com.adobe.utils
34
+ {
35
+ import flash.utils.Dictionary;
36
+
37
+ public class DictionaryUtil
38
+ {
39
+
40
+ /**
41
+ * Returns an Array of all keys within the specified dictionary.
42
+ *
43
+ * @param d The Dictionary instance whose keys will be returned.
44
+ *
45
+ * @return Array of keys contained within the Dictionary
46
+ *
47
+ * @langversion ActionScript 3.0
48
+ * @playerversion Flash 9.0
49
+ * @tiptext
50
+ */
51
+ public static function getKeys(d:Dictionary):Array
52
+ {
53
+ var a:Array = new Array();
54
+
55
+ for (var key:Object in d)
56
+ {
57
+ a.push(key);
58
+ }
59
+
60
+ return a;
61
+ }
62
+
63
+ /**
64
+ * Returns an Array of all values within the specified dictionary.
65
+ *
66
+ * @param d The Dictionary instance whose values will be returned.
67
+ *
68
+ * @return Array of values contained within the Dictionary
69
+ *
70
+ * @langversion ActionScript 3.0
71
+ * @playerversion Flash 9.0
72
+ * @tiptext
73
+ */
74
+ public static function getValues(d:Dictionary):Array
75
+ {
76
+ var a:Array = new Array();
77
+
78
+ for each (var value:Object in d)
79
+ {
80
+ a.push(value);
81
+ }
82
+
83
+ return a;
84
+ }
85
+
86
+ }
87
+ }
@@ -0,0 +1,99 @@
1
+ /*
2
+ Copyright (c) 2008, Adobe Systems Incorporated
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are
7
+ met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice,
10
+ this list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright
13
+ notice, this list of conditions and the following disclaimer in the
14
+ documentation and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of Adobe Systems Incorporated nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+ package com.adobe.utils {
33
+
34
+ import flash.utils.Endian;
35
+
36
+ /**
37
+ * Contains reusable methods for operations pertaining
38
+ * to int values.
39
+ */
40
+ public class IntUtil {
41
+
42
+ /**
43
+ * Rotates x left n bits
44
+ *
45
+ * @langversion ActionScript 3.0
46
+ * @playerversion Flash 9.0
47
+ * @tiptext
48
+ */
49
+ public static function rol ( x:int, n:int ):int {
50
+ return ( x << n ) | ( x >>> ( 32 - n ) );
51
+ }
52
+
53
+ /**
54
+ * Rotates x right n bits
55
+ *
56
+ * @langversion ActionScript 3.0
57
+ * @playerversion Flash 9.0
58
+ * @tiptext
59
+ */
60
+ public static function ror ( x:int, n:int ):uint {
61
+ var nn:int = 32 - n;
62
+ return ( x << nn ) | ( x >>> ( 32 - nn ) );
63
+ }
64
+
65
+ /** String for quick lookup of a hex character based on index */
66
+ private static var hexChars:String = "0123456789abcdef";
67
+
68
+ /**
69
+ * Outputs the hex value of a int, allowing the developer to specify
70
+ * the endinaness in the process. Hex output is lowercase.
71
+ *
72
+ * @param n The int value to output as hex
73
+ * @param bigEndian Flag to output the int as big or little endian
74
+ * @return A string of length 8 corresponding to the
75
+ * hex representation of n ( minus the leading "0x" )
76
+ * @langversion ActionScript 3.0
77
+ * @playerversion Flash 9.0
78
+ * @tiptext
79
+ */
80
+ public static function toHex( n:int, bigEndian:Boolean = false ):String {
81
+ var s:String = "";
82
+
83
+ if ( bigEndian ) {
84
+ for ( var i:int = 0; i < 4; i++ ) {
85
+ s += hexChars.charAt( ( n >> ( ( 3 - i ) * 8 + 4 ) ) & 0xF )
86
+ + hexChars.charAt( ( n >> ( ( 3 - i ) * 8 ) ) & 0xF );
87
+ }
88
+ } else {
89
+ for ( var x:int = 0; x < 4; x++ ) {
90
+ s += hexChars.charAt( ( n >> ( x * 8 + 4 ) ) & 0xF )
91
+ + hexChars.charAt( ( n >> ( x * 8 ) ) & 0xF );
92
+ }
93
+ }
94
+
95
+ return s;
96
+ }
97
+ }
98
+
99
+ }
@@ -0,0 +1,74 @@
1
+ /*
2
+ Copyright (c) 2008, Adobe Systems Incorporated
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are
7
+ met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice,
10
+ this list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright
13
+ notice, this list of conditions and the following disclaimer in the
14
+ documentation and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of Adobe Systems Incorporated nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+ package com.adobe.utils
34
+ {
35
+
36
+ /**
37
+ * Class that contains static utility methods for formatting Numbers
38
+ *
39
+ * @langversion ActionScript 3.0
40
+ * @playerversion Flash 9.0
41
+ * @tiptext
42
+ *
43
+ * @see #mx.formatters.NumberFormatter
44
+ */
45
+ public class NumberFormatter
46
+ {
47
+
48
+ /**
49
+ * Formats a number to include a leading zero if it is a single digit
50
+ * between -1 and 10.
51
+ *
52
+ * @param n The number that will be formatted
53
+ *
54
+ * @return A string with single digits between -1 and 10 padded with a
55
+ * leading zero.
56
+ *
57
+ * @langversion ActionScript 3.0
58
+ * @playerversion Flash 9.0
59
+ * @tiptext
60
+ */
61
+ public static function addLeadingZero(n:Number):String
62
+ {
63
+ var out:String = String(n);
64
+
65
+ if(n < 10 && n > -1)
66
+ {
67
+ out = "0" + out;
68
+ }
69
+
70
+ return out;
71
+ }
72
+
73
+ }
74
+ }
@@ -0,0 +1,239 @@
1
+ /*
2
+ Copyright (c) 2008, Adobe Systems Incorporated
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are
7
+ met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice,
10
+ this list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright
13
+ notice, this list of conditions and the following disclaimer in the
14
+ documentation and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of Adobe Systems Incorporated nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+ package com.adobe.utils
34
+ {
35
+
36
+ /**
37
+ * Class that contains static utility methods for manipulating Strings.
38
+ *
39
+ * @langversion ActionScript 3.0
40
+ * @playerversion Flash 9.0
41
+ * @tiptext
42
+ */
43
+ public class StringUtil
44
+ {
45
+
46
+
47
+ /**
48
+ * Does a case insensitive compare or two strings and returns true if
49
+ * they are equal.
50
+ *
51
+ * @param s1 The first string to compare.
52
+ *
53
+ * @param s2 The second string to compare.
54
+ *
55
+ * @returns A boolean value indicating whether the strings' values are
56
+ * equal in a case sensitive compare.
57
+ *
58
+ * @langversion ActionScript 3.0
59
+ * @playerversion Flash 9.0
60
+ * @tiptext
61
+ */
62
+ public static function stringsAreEqual(s1:String, s2:String,
63
+ caseSensitive:Boolean):Boolean
64
+ {
65
+ if(caseSensitive)
66
+ {
67
+ return (s1 == s2);
68
+ }
69
+ else
70
+ {
71
+ return (s1.toUpperCase() == s2.toUpperCase());
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Removes whitespace from the front and the end of the specified
77
+ * string.
78
+ *
79
+ * @param input The String whose beginning and ending whitespace will
80
+ * will be removed.
81
+ *
82
+ * @returns A String with whitespace removed from the begining and end
83
+ *
84
+ * @langversion ActionScript 3.0
85
+ * @playerversion Flash 9.0
86
+ * @tiptext
87
+ */
88
+ public static function trim(input:String):String
89
+ {
90
+ return StringUtil.ltrim(StringUtil.rtrim(input));
91
+ }
92
+
93
+ /**
94
+ * Removes whitespace from the front of the specified string.
95
+ *
96
+ * @param input The String whose beginning whitespace will will be removed.
97
+ *
98
+ * @returns A String with whitespace removed from the begining
99
+ *
100
+ * @langversion ActionScript 3.0
101
+ * @playerversion Flash 9.0
102
+ * @tiptext
103
+ */
104
+ public static function ltrim(input:String):String
105
+ {
106
+ var size:Number = input.length;
107
+ for(var i:Number = 0; i < size; i++)
108
+ {
109
+ if(input.charCodeAt(i) > 32)
110
+ {
111
+ return input.substring(i);
112
+ }
113
+ }
114
+ return "";
115
+ }
116
+
117
+ /**
118
+ * Removes whitespace from the end of the specified string.
119
+ *
120
+ * @param input The String whose ending whitespace will will be removed.
121
+ *
122
+ * @returns A String with whitespace removed from the end
123
+ *
124
+ * @langversion ActionScript 3.0
125
+ * @playerversion Flash 9.0
126
+ * @tiptext
127
+ */
128
+ public static function rtrim(input:String):String
129
+ {
130
+ var size:Number = input.length;
131
+ for(var i:Number = size; i > 0; i--)
132
+ {
133
+ if(input.charCodeAt(i - 1) > 32)
134
+ {
135
+ return input.substring(0, i);
136
+ }
137
+ }
138
+
139
+ return "";
140
+ }
141
+
142
+ /**
143
+ * Determines whether the specified string begins with the spcified prefix.
144
+ *
145
+ * @param input The string that the prefix will be checked against.
146
+ *
147
+ * @param prefix The prefix that will be tested against the string.
148
+ *
149
+ * @returns True if the string starts with the prefix, false if it does not.
150
+ *
151
+ * @langversion ActionScript 3.0
152
+ * @playerversion Flash 9.0
153
+ * @tiptext
154
+ */
155
+ public static function beginsWith(input:String, prefix:String):Boolean
156
+ {
157
+ return (prefix == input.substring(0, prefix.length));
158
+ }
159
+
160
+ /**
161
+ * Determines whether the specified string ends with the spcified suffix.
162
+ *
163
+ * @param input The string that the suffic will be checked against.
164
+ *
165
+ * @param prefix The suffic that will be tested against the string.
166
+ *
167
+ * @returns True if the string ends with the suffix, false if it does not.
168
+ *
169
+ * @langversion ActionScript 3.0
170
+ * @playerversion Flash 9.0
171
+ * @tiptext
172
+ */
173
+ public static function endsWith(input:String, suffix:String):Boolean
174
+ {
175
+ return (suffix == input.substring(input.length - suffix.length));
176
+ }
177
+
178
+ /**
179
+ * Removes all instances of the remove string in the input string.
180
+ *
181
+ * @param input The string that will be checked for instances of remove
182
+ * string
183
+ *
184
+ * @param remove The string that will be removed from the input string.
185
+ *
186
+ * @returns A String with the remove string removed.
187
+ *
188
+ * @langversion ActionScript 3.0
189
+ * @playerversion Flash 9.0
190
+ * @tiptext
191
+ */
192
+ public static function remove(input:String, remove:String):String
193
+ {
194
+ return StringUtil.replace(input, remove, "");
195
+ }
196
+
197
+ /**
198
+ * Replaces all instances of the replace string in the input string
199
+ * with the replaceWith string.
200
+ *
201
+ * @param input The string that instances of replace string will be
202
+ * replaces with removeWith string.
203
+ *
204
+ * @param replace The string that will be replaced by instances of
205
+ * the replaceWith string.
206
+ *
207
+ * @param replaceWith The string that will replace instances of replace
208
+ * string.
209
+ *
210
+ * @returns A new String with the replace string replaced with the
211
+ * replaceWith string.
212
+ *
213
+ * @langversion ActionScript 3.0
214
+ * @playerversion Flash 9.0
215
+ * @tiptext
216
+ */
217
+ public static function replace(input:String, replace:String, replaceWith:String):String
218
+ {
219
+ return input.split(replace).join(replaceWith);
220
+ }
221
+
222
+
223
+ /**
224
+ * Specifies whether the specified string is either non-null, or contains
225
+ * characters (i.e. length is greater that 0)
226
+ *
227
+ * @param s The string which is being checked for a value
228
+ *
229
+ * @langversion ActionScript 3.0
230
+ * @playerversion Flash 9.0
231
+ * @tiptext
232
+ */
233
+ public static function stringHasValue(s:String):Boolean
234
+ {
235
+ //todo: this needs a unit test
236
+ return (s != null && s.length > 0);
237
+ }
238
+ }
239
+ }
@@ -0,0 +1,168 @@
1
+ /*
2
+ Copyright (c) 2008, Adobe Systems Incorporated
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are
7
+ met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice,
10
+ this list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright
13
+ notice, this list of conditions and the following disclaimer in the
14
+ documentation and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of Adobe Systems Incorporated nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ */
32
+
33
+ package com.adobe.utils
34
+ {
35
+
36
+ public class XMLUtil
37
+ {
38
+ /**
39
+ * Constant representing a text node type returned from XML.nodeKind.
40
+ *
41
+ * @see XML.nodeKind()
42
+ *
43
+ * @langversion ActionScript 3.0
44
+ * @playerversion Flash 9.0
45
+ */
46
+ public static const TEXT:String = "text";
47
+
48
+ /**
49
+ * Constant representing a comment node type returned from XML.nodeKind.
50
+ *
51
+ * @see XML.nodeKind()
52
+ *
53
+ * @langversion ActionScript 3.0
54
+ * @playerversion Flash 9.0
55
+ */
56
+ public static const COMMENT:String = "comment";
57
+
58
+ /**
59
+ * Constant representing a processing instruction type returned from XML.nodeKind.
60
+ *
61
+ * @see XML.nodeKind()
62
+ *
63
+ * @langversion ActionScript 3.0
64
+ * @playerversion Flash 9.0
65
+ */
66
+ public static const PROCESSING_INSTRUCTION:String = "processing-instruction";
67
+
68
+ /**
69
+ * Constant representing an attribute type returned from XML.nodeKind.
70
+ *
71
+ * @see XML.nodeKind()
72
+ *
73
+ * @langversion ActionScript 3.0
74
+ * @playerversion Flash 9.0
75
+ */
76
+ public static const ATTRIBUTE:String = "attribute";
77
+
78
+ /**
79
+ * Constant representing a element type returned from XML.nodeKind.
80
+ *
81
+ * @see XML.nodeKind()
82
+ *
83
+ * @langversion ActionScript 3.0
84
+ * @playerversion Flash 9.0
85
+ */
86
+ public static const ELEMENT:String = "element";
87
+
88
+ /**
89
+ * Checks whether the specified string is valid and well formed XML.
90
+ *
91
+ * @param data The string that is being checked to see if it is valid XML.
92
+ *
93
+ * @return A Boolean value indicating whether the specified string is
94
+ * valid XML.
95
+ *
96
+ * @langversion ActionScript 3.0
97
+ * @playerversion Flash 9.0
98
+ */
99
+ public static function isValidXML(data:String):Boolean
100
+ {
101
+ var xml:XML;
102
+
103
+ try
104
+ {
105
+ xml = new XML(data);
106
+ }
107
+ catch(e:Error)
108
+ {
109
+ return false;
110
+ }
111
+
112
+ if(xml.nodeKind() != XMLUtil.ELEMENT)
113
+ {
114
+ return false;
115
+ }
116
+
117
+ return true;
118
+ }
119
+
120
+ /**
121
+ * Returns the next sibling of the specified node relative to the node's parent.
122
+ *
123
+ * @param x The node whose next sibling will be returned.
124
+ *
125
+ * @return The next sibling of the node. null if the node does not have
126
+ * a sibling after it, or if the node has no parent.
127
+ *
128
+ * @langversion ActionScript 3.0
129
+ * @playerversion Flash 9.0
130
+ */
131
+ public static function getNextSibling(x:XML):XML
132
+ {
133
+ return XMLUtil.getSiblingByIndex(x, 1);
134
+ }
135
+
136
+ /**
137
+ * Returns the sibling before the specified node relative to the node's parent.
138
+ *
139
+ * @param x The node whose sibling before it will be returned.
140
+ *
141
+ * @return The sibling before the node. null if the node does not have
142
+ * a sibling before it, or if the node has no parent.
143
+ *
144
+ * @langversion ActionScript 3.0
145
+ * @playerversion Flash 9.0
146
+ */
147
+ public static function getPreviousSibling(x:XML):XML
148
+ {
149
+ return XMLUtil.getSiblingByIndex(x, -1);
150
+ }
151
+
152
+ protected static function getSiblingByIndex(x:XML, count:int):XML
153
+ {
154
+ var out:XML;
155
+
156
+ try
157
+ {
158
+ out = x.parent().children()[x.childIndex() + count];
159
+ }
160
+ catch(e:Error)
161
+ {
162
+ return null;
163
+ }
164
+
165
+ return out;
166
+ }
167
+ }
168
+ }