This is an automated email from the ASF dual-hosted git repository.
harbs pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new 4bf4b6c Added string utils
4bf4b6c is described below
commit 4bf4b6cc73cdd74d21bcb17a90373242301a45ce
Author: Harbs <[email protected]>
AuthorDate: Thu Jan 4 15:27:29 2018 -0500
Added string utils
---
.../projects/Core/src/main/royale/CoreClasses.as | 6 ++
.../org/apache/royale/utils/string/contains.as} | 27 ++++----
.../royale/org/apache/royale/utils/string/trim.as | 54 ++++++++++++++++
.../org/apache/royale/utils/string/trimLeft.as} | 40 ++++++++----
.../org/apache/royale/utils/string/trimRight.as} | 42 ++++++++----
.../src/test/royale/flexUnitTests/CoreTester.as | 1 +
.../test/royale/flexUnitTests/StringUtilsTest.as | 74 ++++++++++++++++++++++
7 files changed, 207 insertions(+), 37 deletions(-)
diff --git a/frameworks/projects/Core/src/main/royale/CoreClasses.as
b/frameworks/projects/Core/src/main/royale/CoreClasses.as
index a74ad70..2d13773 100644
--- a/frameworks/projects/Core/src/main/royale/CoreClasses.as
+++ b/frameworks/projects/Core/src/main/royale/CoreClasses.as
@@ -232,6 +232,12 @@ internal class CoreClasses
import org.apache.royale.utils.loadBeadFromValuesManager;
loadBeadFromValuesManager;
import org.apache.royale.utils.array.rangeCheck; rangeCheck;
+
+ import org.apache.royale.utils.string.contains; contains;
+ import org.apache.royale.utils.string.trim; trim;
+ import org.apache.royale.utils.string.trimRight; trimRight;
+ import org.apache.royale.utils.string.trimLeft; trimLeft;
+
import org.apache.royale.utils.date.addDays; addDays;
import org.apache.royale.utils.date.addHours; addHours;
import org.apache.royale.utils.date.addMinutes; addMinutes;
diff --git
a/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/contains.as
similarity index 59%
copy from frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
copy to
frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/contains.as
index 3c9c5bf..2e16d52 100644
--- a/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
+++
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/contains.as
@@ -4,7 +4,7 @@
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
-// (the "License"); you may not use this file except in compliance with
+// (the "Licens"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -16,17 +16,20 @@
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
-package flexUnitTests
+package org.apache.royale.utils.string
{
- [Suite]
- [RunWith("org.flexunit.runners.Suite")]
- public class CoreTester
+ import org.apache.royale.debugging.assert;
+ /**
+ * Checks whether a string contains the specified substring.
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9
+ */
+ public function contains(string:String,value:String):Boolean
{
- public var strandTesterTest:StrandTesterTest;
- public var binaryDataTesterTest:BinaryDataTesterTest;
- public var arrayUtilsTest:ArrayUtilsTest;
- public var dateUtilsTest:DateUtilsTest;
- public var keyConverterTest:KeyConverterTest;
- public var keyboardEventConverterTest:KeyboardEventConverterTest;
+ assert(string != null,"contains() cannot be called with a null
string");
+ assert(string != null,"contains() cannot be called with a null
substring");
+ return string.indexOf(value) != -1;
}
-}
+}
\ No newline at end of file
diff --git
a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/trim.as
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/trim.as
new file mode 100644
index 0000000..2d93f90
--- /dev/null
+++
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/trim.as
@@ -0,0 +1,54 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "Licens"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.utils.string
+{
+ import org.apache.royale.debugging.assert;
+ /**
+ * Trims all whitespace off the beginning and end of a string.
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9
+ */
+ public function trim(str:String):String
+ {
+ assert(str != null,"trim() cannot be called on null");
+
+ COMPILE::SWF
+ {
+ var startIndex:int = 0;
+ while (isWhitespace(str.charAt(startIndex)))
+ ++startIndex;
+
+ var endIndex:int = str.length - 1;
+ while (isWhitespace(str.charAt(endIndex)))
+ --endIndex;
+
+ if (endIndex >= startIndex)
+ return str.slice(startIndex, endIndex + 1);
+ else
+ return "";
+ }
+
+ COMPILE::JS
+ {
+ return str.trim();
+ }
+ }
+}
\ No newline at end of file
diff --git
a/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/trimLeft.as
similarity index 53%
copy from frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
copy to
frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/trimLeft.as
index 3c9c5bf..0842830 100644
--- a/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
+++
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/trimLeft.as
@@ -4,7 +4,7 @@
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
-// (the "License"); you may not use this file except in compliance with
+// (the "Licens"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -16,17 +16,31 @@
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
-package flexUnitTests
+package org.apache.royale.utils.string
{
- [Suite]
- [RunWith("org.flexunit.runners.Suite")]
- public class CoreTester
+ import org.apache.royale.debugging.assert;
+ /**
+ * Checks that an index falls within the allowable range of an array.
+ * Returns true if it's valid, false if not.
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9
+ */
+ public function trimLeft(str:String):String
{
- public var strandTesterTest:StrandTesterTest;
- public var binaryDataTesterTest:BinaryDataTesterTest;
- public var arrayUtilsTest:ArrayUtilsTest;
- public var dateUtilsTest:DateUtilsTest;
- public var keyConverterTest:KeyConverterTest;
- public var keyboardEventConverterTest:KeyboardEventConverterTest;
- }
-}
+ assert(str != null,"trim() cannot be called on null");
+
+ COMPILE::SWF{
+ var startIndex:int = 0;
+ while (isWhitespace(str.charAt(startIndex)))
+ ++startIndex;
+
+ return str.slice(startIndex);
+ }
+
+ COMPILE::JS{
+ return str.trimLeft();
+ }
+ }
+}
\ No newline at end of file
diff --git
a/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/trimRight.as
similarity index 50%
copy from frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
copy to
frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/trimRight.as
index 3c9c5bf..3370286 100644
--- a/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
+++
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/string/trimRight.as
@@ -4,7 +4,7 @@
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
-// (the "License"); you may not use this file except in compliance with
+// (the "Licens"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
@@ -16,17 +16,35 @@
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
-package flexUnitTests
+package org.apache.royale.utils.string
{
- [Suite]
- [RunWith("org.flexunit.runners.Suite")]
- public class CoreTester
+ import org.apache.royale.debugging.assert;
+ /**
+ * Trims all whitespace off the end of a string.
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9
+ */
+ public function trimRight(str:String):String
{
- public var strandTesterTest:StrandTesterTest;
- public var binaryDataTesterTest:BinaryDataTesterTest;
- public var arrayUtilsTest:ArrayUtilsTest;
- public var dateUtilsTest:DateUtilsTest;
- public var keyConverterTest:KeyConverterTest;
- public var keyboardEventConverterTest:KeyboardEventConverterTest;
+ assert(str != null,"trim() cannot be called on null");
+
+ COMPILE::SWF{
+ var startIndex:int = 0;
+
+ var endIndex:int = str.length - 1;
+ while (isWhitespace(str.charAt(endIndex)))
+ --endIndex;
+
+ if (endIndex >= startIndex)
+ return str.slice(startIndex, endIndex + 1);
+ else
+ return "";
+ }
+
+ COMPILE::JS{
+ return str.trimRight();
+ }
}
-}
+}
\ No newline at end of file
diff --git
a/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
b/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
index 3c9c5bf..2f99400 100644
--- a/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
+++ b/frameworks/projects/Core/src/test/royale/flexUnitTests/CoreTester.as
@@ -28,5 +28,6 @@ package flexUnitTests
public var dateUtilsTest:DateUtilsTest;
public var keyConverterTest:KeyConverterTest;
public var keyboardEventConverterTest:KeyboardEventConverterTest;
+ public var stringUtilsTest:StringUtilsTest;
}
}
diff --git
a/frameworks/projects/Core/src/test/royale/flexUnitTests/StringUtilsTest.as
b/frameworks/projects/Core/src/test/royale/flexUnitTests/StringUtilsTest.as
new file mode 100644
index 0000000..5390817
--- /dev/null
+++ b/frameworks/projects/Core/src/test/royale/flexUnitTests/StringUtilsTest.as
@@ -0,0 +1,74 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package flexUnitTests
+{
+ import org.apache.royale.utils.string.*;
+ import org.apache.royale.test.asserts.*;
+
+ public class StringUtilsTest
+ {
+ [Before]
+ public function setUp():void
+ {
+ }
+
+ [After]
+ public function tearDown():void
+ {
+ }
+
+ [BeforeClass]
+ public static function setUpBeforeClass():void
+ {
+ }
+
+ [AfterClass]
+ public static function tearDownAfterClass():void
+ {
+ }
+
+ [Test]
+ public function testContains():void
+ {
+ assertTrue(contains("food","foo"),"food contains foo");
+ assertTrue(!contains("foo","food"),"foo does not contain food");
+ assertTrue(!contains("food","baz"),"food does not contain baz");
+ }
+
+ [Test]
+ public function testTrim():void
+ {
+ assertTrue(trim(" foo ") == "foo","Should be 'foo'");
+ }
+
+ [Test]
+ public function testTrimLeft():void
+ {
+ assertTrue(trimLeft(" foo ") == "foo ","Should be 'foo ' (with
spaces after)");
+ }
+
+ [Test]
+ public function testTrimRight():void
+ {
+ assertTrue(trimRight(" foo ") == " foo","Should be ' foo'
(with spaces before)");
+ }
+
+
+ }
+}
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].