[sword-svn] r2564 - in trunk: bindings/java-jni/jni src/modules/filters tests
scribe at crosswire.org
scribe at crosswire.org
Mon Oct 4 16:10:01 MST 2010
Author: scribe
Date: 2010-10-04 16:10:01 -0700 (Mon, 04 Oct 2010)
New Revision: 2564
Modified:
trunk/bindings/java-jni/jni/swordstub.cpp
trunk/src/modules/filters/utf8utf16.cpp
trunk/tests/filtertest.cpp
Log:
Added a search limit to the android bindings
Fixed a 1 off bug for size returned for utf16 buffers
Changed filtertest to show how to cast to a UTF16 stream after conversion
Modified: trunk/bindings/java-jni/jni/swordstub.cpp
===================================================================
--- trunk/bindings/java-jni/jni/swordstub.cpp 2010-10-04 08:38:11 UTC (rev 2563)
+++ trunk/bindings/java-jni/jni/swordstub.cpp 2010-10-04 23:10:01 UTC (rev 2564)
@@ -1117,6 +1117,7 @@
init();
+ const int MAX_RETURN_COUNT = 200;
const char *expression = env->GetStringUTFChars(expressionJS, NULL);
const char *scope = env->GetStringUTFChars(scopeJS, NULL);
@@ -1149,6 +1150,8 @@
int count = 0;
for (result = sword::TOP; !result.Error(); result++) count++;
+ if (count > MAX_RETURN_COUNT) count = MAX_RETURN_COUNT;
+
ret = (jobjectArray) env->NewObjectArray(count, clazzSearchHit, NULL);
// if we're sorted by score, let's re-sort by verse, because Java can always re-sort by score
@@ -1166,6 +1169,7 @@
fieldID = env->GetFieldID(clazzSearchHit, "score", "J"); env->SetLongField(searchHit, fieldID, (long)result.getElement()->userData);
env->SetObjectArrayElement(ret, i++, searchHit);
+ if (i > MAX_RETURN_COUNT) break;
}
}
Modified: trunk/src/modules/filters/utf8utf16.cpp
===================================================================
--- trunk/src/modules/filters/utf8utf16.cpp 2010-10-04 08:38:11 UTC (rev 2563)
+++ trunk/src/modules/filters/utf8utf16.cpp 2010-10-04 23:10:01 UTC (rev 2564)
@@ -63,6 +63,7 @@
}
text.setSize(text.size()+2);
*((__u16 *)(text.getRawData()+(text.size()-2))) = (__u16)0;
+ text.setSize(text.size()-2);
return 0;
Modified: trunk/tests/filtertest.cpp
===================================================================
--- trunk/tests/filtertest.cpp 2010-10-04 08:38:11 UTC (rev 2563)
+++ trunk/tests/filtertest.cpp 2010-10-04 23:10:01 UTC (rev 2564)
@@ -20,6 +20,7 @@
#include <filemgr.h>
#include <papyriplain.h>
#include <utf8utf16.h>
+#include <sysdata.h>
//#include <swmgr.h>
#ifndef NO_SWORD_NAMESPACE
using namespace sword;
@@ -35,31 +36,42 @@
SWBuf lineBuffer = "This is t<e>xt which has papy-\nri markings in it.\n L[et's be] sure it gets--\n cleaned up well for s(earching)";
- std::cout << "Original:\n\n";
+ if (argc > 1 && !strcmp(argv[1], "-v")) {
+ std::cout << "Original:\n\n";
- while (!fd || FileMgr::getLine(fd, lineBuffer)) {
- cout << lineBuffer << "\n";
- if (!fd) break;
+ while (!fd || FileMgr::getLine(fd, lineBuffer)) {
+ cout << lineBuffer << "\n";
+ if (!fd) break;
+ }
+
+ cout << "\n\n-------\n\n";
}
- cout << "\n\n-------\n\n";
-
if (fd) {
FileMgr::getSystemFileMgr()->close(fd);
fd = FileMgr::getSystemFileMgr()->open(argv[1], FileMgr::RDONLY);
}
+ cout << "\xff\xfe"; // UTF16LE file signature
+
while (!fd || FileMgr::getLine(fd, lineBuffer)) {
+ lineBuffer += "\n";
filter.processText(lineBuffer);
- for (unsigned int i = 0; i < lineBuffer.size(); i++) {
+
+/* Simply way to output byte stream
+ for (unsigned int i = 0; i < lineBuffer.size(); ++i) {
std::cout << lineBuffer[i];
}
- cout << "\n";
+*/
+// Example showing safe to cast to u16 stream
+ unsigned int size = lineBuffer.size() / 2;
+ __u16 *wcharBuf = (__u16 *)lineBuffer.getRawData();
+ for (unsigned int i = 0; i < size; ++i) {
+ std::wcout << (wchar_t)wcharBuf[i]; // must cast for correct output and because wchar_t is different size on linux we couldn't declare out wcharBuf a wchar_t *
+ }
if (!fd) break;
}
- std::cout << "\n\n+++++++\n";
-
if (fd) {
FileMgr::getSystemFileMgr()->close(fd);
}
More information about the sword-cvs
mailing list