[sword-svn] r2982 - in trunk: src/utilfuns tests

scribe at crosswire.org scribe at crosswire.org
Sun Sep 15 06:33:03 MST 2013


Author: scribe
Date: 2013-09-15 06:33:03 -0700 (Sun, 15 Sep 2013)
New Revision: 2982

Modified:
   trunk/src/utilfuns/utilstr.cpp
   trunk/tests/swbuftest.cpp
Log:
added a fix to yesterdays commit for wcharToUTF8 impl.  Added a test for round trip of these methods


Modified: trunk/src/utilfuns/utilstr.cpp
===================================================================
--- trunk/src/utilfuns/utilstr.cpp	2013-09-15 00:05:26 UTC (rev 2981)
+++ trunk/src/utilfuns/utilstr.cpp	2013-09-15 13:33:03 UTC (rev 2982)
@@ -255,15 +255,16 @@
 		retVal.setSize(1);
 	}
 	else if (uchar < 0x800) {
+		retVal.setSize(2);
 		i = uchar & 0x3f;
 		retVal[1] = (unsigned char)(0x80 | i);
 		uchar >>= 6;
 
 		i = uchar & 0x1f;
 		retVal[0] = (unsigned char)(0xc0 | i);
-		retVal.setSize(2);
 	}
 	else if (uchar < 0x10000) {
+		retVal.setSize(3);
 		i = uchar & 0x3f;
 		retVal[2] = (unsigned char)(0x80 | i);
 		uchar >>= 6;
@@ -274,9 +275,9 @@
 
 		i = uchar & 0x0f;
 		retVal[0] = (unsigned char)(0xe0 | i);
-		retVal.setSize(3);
 	}
 	else if (uchar < 0x200000) {
+		retVal.setSize(4);
 		i = uchar & 0x3f;
 		retVal[3] = (unsigned char)(0x80 | i);
 		uchar >>= 6;
@@ -291,9 +292,9 @@
 
 		i = uchar & 0x07;
 		retVal[0] = (unsigned char)(0xf0 | i);
-		retVal.setSize(4);
 	}
 	else if (uchar < 0x4000000) {
+		retVal.setSize(5);
 		i = uchar & 0x3f;
 		retVal[4] = (unsigned char)(0x80 | i);
 		uchar >>= 6;
@@ -312,9 +313,9 @@
 
 		i = uchar & 0x03;
 		retVal[0] = (unsigned char)(0xf8 | i);
-		retVal.setSize(5);
 	}
 	else if (uchar < 0x80000000) {
+		retVal.setSize(6);
 		i = uchar & 0x3f;
 		retVal[5] = (unsigned char)(0x80 | i);
 		uchar >>= 6;
@@ -337,7 +338,6 @@
 
 		i = uchar & 0x01;
 		retVal[0] = (unsigned char)(0xfc | i);
-		retVal.setSize(6);
 	}
 
 	return retVal;

Modified: trunk/tests/swbuftest.cpp
===================================================================
--- trunk/tests/swbuftest.cpp	2013-09-15 00:05:26 UTC (rev 2981)
+++ trunk/tests/swbuftest.cpp	2013-09-15 13:33:03 UTC (rev 2982)
@@ -26,6 +26,8 @@
 #define BASEI 102400000L
 
 #include <swbuf.h>
+#include <utilstr.h>
+
 typedef sword::SWBuf StringType;
 
 //#include <string>
@@ -33,6 +35,8 @@
 
 using std::cout;
 using std::cerr;
+using sword::utf8ToWChar;
+using sword::wcharToUTF8;
 
 void markTime() {
 	static clock_t start = clock();
@@ -137,6 +141,8 @@
 }
 
 int main(int argc, char **argv) {
+
+	bool showTimings = !(argc > 1 && !strcmp(argv[1], "--no-timings"));
 	StringType x;
 	cout << "x should be (): (" << x << ")\n";
 	cout << "size should be 0: " << x.size() << "\n";
@@ -157,6 +163,11 @@
 	cout << "Prefix should be (prefix): " << prefixTest.stripPrefix(':') << "\n";
 	cout << "Value should be (value): " << prefixTest << "\n";
 
+	x = utf8ToWChar("ⲉⲛⲧⲁⲡⲛⲟⲩⲧⲉ");
+	cout << (wchar_t *)x.getRawData() << "\n";
+	x = wcharToUTF8((wchar_t *)x.getRawData());
+	cout << x << "\n";
+
 //	y.appendFormatted(" from %d %s running %02.05f miles", 4, "dogs", 1.9f);
 //	cout << "should be (hello wurld hello wurld from 4 dogs running 1.90000 miles): (" << y << ")\n";
 //	y += '!';
@@ -164,18 +175,18 @@
 //	y.append(y.c_str(),5);
 //	cout << "should be (hello wurld hello wurld from 4 dogs running 1.90000 miles!hello): (" << y << ")\n";
 
-	markTime();
+	if (showTimings) markTime();
 	appendChTest();
-	markTime();
+	if (showTimings) markTime();
 	appendStringTest();
-	markTime();
+	if (showTimings) markTime();
 	subscriptTest();
-	markTime();
+	if (showTimings) markTime();
 	ctorAssignTest();
-	markTime();
+	if (showTimings) markTime();
 	compareTest();
-	markTime();
+	if (showTimings) markTime();
 	insertStringTest();
-	markTime();
+	if (showTimings) markTime();
 }
 




More information about the sword-cvs mailing list