You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2013/11/08 00:09:09 UTC
git commit: Some additional utility methods and tests
Updated Branches:
refs/heads/trunk 2d9ce2f36 -> c6d121450
Some additional utility methods and tests
Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/c6d12145
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/c6d12145
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/c6d12145
Branch: refs/heads/trunk
Commit: c6d121450b3f7b8a60b811b1fb887ebb554b5092
Parents: 2d9ce2f
Author: Timothy Bish <ta...@gmai.com>
Authored: Thu Nov 7 18:09:05 2013 -0500
Committer: Timothy Bish <ta...@gmai.com>
Committed: Thu Nov 7 18:09:05 2013 -0500
----------------------------------------------------------------------
activemq-cpp/src/main/decaf/lang/String.cpp | 44 +++++++++++++++
activemq-cpp/src/main/decaf/lang/String.h | 56 ++++++++++++++++++++
activemq-cpp/src/test/decaf/lang/StringTest.cpp | 40 ++++++++++++++
activemq-cpp/src/test/decaf/lang/StringTest.h | 8 +++
4 files changed, 148 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/c6d12145/activemq-cpp/src/main/decaf/lang/String.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/lang/String.cpp b/activemq-cpp/src/main/decaf/lang/String.cpp
index 6070df0..80100c1 100644
--- a/activemq-cpp/src/main/decaf/lang/String.cpp
+++ b/activemq-cpp/src/main/decaf/lang/String.cpp
@@ -785,6 +785,50 @@ bool String::equalsIgnoreCase(const char* string) const {
}
////////////////////////////////////////////////////////////////////////////////
+int String::findFirstOf(const String& chars) const {
+ return findFirstOf(chars, 0);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int String::findFirstOf(const String& chars, int start) const {
+ if (start < contents->length) {
+ if (start < 0) {
+ start = 0;
+ }
+
+ for (int i = contents->offset + start; i < contents->offset + contents->length; i++) {
+ char c = contents->value[i];
+ if (chars.indexOf(c) != -1) {
+ return i;
+ }
+ }
+ }
+ return -1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int String::findFirstNotOf(const String& chars) const {
+ return findFirstNotOf(chars, 0);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int String::findFirstNotOf(const String& chars, int start) const {
+ if (start < contents->length) {
+ if (start < 0) {
+ start = 0;
+ }
+
+ for (int i = contents->offset + start; i < contents->offset + contents->length; i++) {
+ char c = contents->value[i];
+ if (chars.indexOf(c) == -1) {
+ return i;
+ }
+ }
+ }
+ return -1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
int String::hashCode() const {
if (contents->hashCode == 0) {
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/c6d12145/activemq-cpp/src/main/decaf/lang/String.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/lang/String.h b/activemq-cpp/src/main/decaf/lang/String.h
index 722942b..8a5ec88 100644
--- a/activemq-cpp/src/main/decaf/lang/String.h
+++ b/activemq-cpp/src/main/decaf/lang/String.h
@@ -534,6 +534,62 @@ namespace lang {
bool equalsIgnoreCase(const char* string) const;
/**
+ * Searches in this string for the first index of any character in the specified
+ * String. The search for the matching characters starts at the beginning and moves
+ * towards the end of this string.
+ *
+ * @param string
+ * the characters to find the first of within this String.
+ *
+ * @return the index of the first character of the specified string in this
+ * string, -1 if none of the characters in the String exist in this String.
+ */
+ int findFirstOf(const String& chars) const;
+
+ /**
+ * Searches in this string for the first index of any character in the specified
+ * String. The search for the matching characters starts at the given index and moves
+ * towards the end of this string.
+ *
+ * @param chars
+ * the characters to find the first of within this String.
+ * @param start
+ * the starting offset.
+ *
+ * @return the index of the first character of the specified string in this
+ * string, -1 if none of the characters in the String exist in this String.
+ */
+ int findFirstOf(const String& chars, int start) const;
+
+ /**
+ * Searches in this string for the first index of any character that is not in the
+ * specified String. The search for the non-matching characters starts at the beginning
+ * and moves towards the end of this string.
+ *
+ * @param chars
+ * the characters to find the first non-matching index of within this String.
+ *
+ * @return the index of the first character not in the specified string in this
+ * string, -1 if all of the characters in the given String exist in this String.
+ */
+ int findFirstNotOf(const String& chars) const;
+
+ /**
+ * Searches in this string for the first index of any character that is not in the
+ * specified String. The search for the non-matching characters starts at the given index
+ * and moves towards the end of this string.
+ *
+ * @param chars
+ * the characters to find the first non-matching index of within this String.
+ * @param start
+ * the starting offset.
+ *
+ * @return the index of the first character not in the specified string in this
+ * string, -1 if all of the characters in the given String exist in this String.
+ */
+ int findFirstNotOf(const String& chars, int start) const;
+
+ /**
* Returns a hash code for this String instance, the hash code for an empty
* String will always be zero.
*
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/c6d12145/activemq-cpp/src/test/decaf/lang/StringTest.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test/decaf/lang/StringTest.cpp b/activemq-cpp/src/test/decaf/lang/StringTest.cpp
index 604f211..d1e474e 100644
--- a/activemq-cpp/src/test/decaf/lang/StringTest.cpp
+++ b/activemq-cpp/src/test/decaf/lang/StringTest.cpp
@@ -540,6 +540,46 @@ void StringTest::testEqualsIgnoreCaseStdString() {
}
////////////////////////////////////////////////////////////////////////////////
+void StringTest::testFindFirstOf() {
+
+ const String input("HelloWorld");
+
+ CPPUNIT_ASSERT_EQUAL(0, input.findFirstOf("H"));
+ CPPUNIT_ASSERT_EQUAL(-1, input.findFirstOf("z"));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StringTest::testFindFirstOf2() {
+
+ const String input("HelloWorld");
+
+ CPPUNIT_ASSERT_EQUAL(0, input.findFirstOf("H", 0));
+ CPPUNIT_ASSERT_EQUAL(0, input.findFirstOf("H", -1));
+ CPPUNIT_ASSERT_EQUAL(-1, input.findFirstOf("H", 1));
+ CPPUNIT_ASSERT_EQUAL(-1, input.findFirstOf("H", 25));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StringTest::testFindFirstNotOf() {
+
+ const String input("HelloWorld");
+
+ CPPUNIT_ASSERT_EQUAL(1, input.findFirstNotOf("H"));
+ CPPUNIT_ASSERT_EQUAL(0, input.findFirstNotOf("z"));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StringTest::testFindFirstNotOf2() {
+
+ const String input("HelloWorld");
+
+ CPPUNIT_ASSERT_EQUAL(5, input.findFirstNotOf("Hello", 5));
+ CPPUNIT_ASSERT_EQUAL(0, input.findFirstNotOf("z", -1));
+ CPPUNIT_ASSERT_EQUAL(1, input.findFirstNotOf("H", 1));
+ CPPUNIT_ASSERT_EQUAL(-1, input.findFirstNotOf("H", 25));
+}
+
+////////////////////////////////////////////////////////////////////////////////
void StringTest::testIndexOfChar() {
const String input("HelloWorld");
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/c6d12145/activemq-cpp/src/test/decaf/lang/StringTest.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test/decaf/lang/StringTest.h b/activemq-cpp/src/test/decaf/lang/StringTest.h
index e482bf4..5181065 100644
--- a/activemq-cpp/src/test/decaf/lang/StringTest.h
+++ b/activemq-cpp/src/test/decaf/lang/StringTest.h
@@ -97,6 +97,10 @@ namespace lang {
CPPUNIT_TEST( testOperatorPlusString );
CPPUNIT_TEST( testOperatorPlusStdString );
CPPUNIT_TEST( testOperatorPlusCString );
+ CPPUNIT_TEST( testFindFirstOf );
+ CPPUNIT_TEST( testFindFirstOf2 );
+ CPPUNIT_TEST( testFindFirstNotOf );
+ CPPUNIT_TEST( testFindFirstNotOf2 );
CPPUNIT_TEST_SUITE_END();
public:
@@ -137,6 +141,10 @@ namespace lang {
void testIndexOfChar2();
void testIndexOfString();
void testIndexOfString2();
+ void testFindFirstOf();
+ void testFindFirstOf2();
+ void testFindFirstNotOf();
+ void testFindFirstNotOf2();
void testIndexOfStdString();
void testIndexOfStdString2();
void testIndexOfCString();