[sword-svn] r3649 - in trunk: bindings/Android bindings/java-jni/jni include src/modules src/utilfuns
scribe at crosswire.org
scribe at crosswire.org
Wed Jun 12 00:01:48 MST 2019
Author: scribe
Date: 2019-06-12 00:01:48 -0700 (Wed, 12 Jun 2019)
New Revision: 3649
Modified:
trunk/bindings/Android/Makefile
trunk/bindings/java-jni/jni/swordstub.cpp
trunk/include/swbuf.h
trunk/src/modules/swmodule.cpp
trunk/src/utilfuns/swbuf.cpp
Log:
added a new optimizized SWBuf::toUpper() to uppercase an SWBuf. Fixed java-jni StringMgr implementation
Modified: trunk/bindings/Android/Makefile
===================================================================
--- trunk/bindings/Android/Makefile 2019-06-11 01:39:52 UTC (rev 3648)
+++ trunk/bindings/Android/Makefile 2019-06-12 07:01:48 UTC (rev 3649)
@@ -4,7 +4,6 @@
debug: javawrapper
rm -rf ../cordova/cordova-plugin-crosswire-sword/libs/android/*
-# cp -a SWORD/app/build/intermediates/cmake/debug/obj/* ../cordova/cordova-plugin-crosswire-sword/libs/android/
cp -a SWORD/app/build/intermediates/cmake/release/obj/* ../cordova/cordova-plugin-crosswire-sword/libs/android/
javawrapper:
Modified: trunk/bindings/java-jni/jni/swordstub.cpp
===================================================================
--- trunk/bindings/java-jni/jni/swordstub.cpp 2019-06-11 01:39:52 UTC (rev 3648)
+++ trunk/bindings/java-jni/jni/swordstub.cpp 2019-06-12 07:01:48 UTC (rev 3649)
@@ -161,6 +161,7 @@
class AndroidStringMgr : public StringMgr {
public:
virtual char *upperUTF8(char *buf, unsigned int maxLen = 0) const {
+ if (!maxLen) maxLen = strlen(buf)+1;
JNIEnv *myThreadsEnv = 0;
// double check it's all ok
@@ -174,9 +175,10 @@
}
if (myThreadsEnv) {
- long bufLen = strlen(buf);
+ SWBuf validBuf = assureValidUTF8(buf);
+ long bufLen = validBuf.size();
jbyteArray array = myThreadsEnv->NewByteArray(bufLen);
- myThreadsEnv->SetByteArrayRegion(array, 0, bufLen, (const jbyte *)buf);
+ myThreadsEnv->SetByteArrayRegion(array, 0, bufLen, (const jbyte *)validBuf.c_str());
jstring strEncode = myThreadsEnv->NewStringUTF("UTF-8");
jclass cls = myThreadsEnv->FindClass("java/lang/String");
jmethodID ctor = myThreadsEnv->GetMethodID(cls, "<init>", "([BLjava/lang/String;)V");
@@ -1715,9 +1717,17 @@
struct pu {
- pu(JNIEnv *env, jobject pr) : env(env), progressReporter(pr), last(0) {}
+ pu(JNIEnv *env, jobject pr) : env(env), progressReporter(pr), last(0) {
+SWLog::getSystemLog()->logDebug("building progressReporter");
+ jclass cls = env->GetObjectClass(progressReporter);
+ mid = env->GetMethodID(cls, "progressReport", "(I)V");
+ env->DeleteLocalRef(cls);
+ }
+ ~pu() {
+ }
JNIEnv *env;
jobject progressReporter;
+ jmethodID mid;
char last;
};
@@ -1730,12 +1740,9 @@
if (percent != p->last) {
p->last = percent;
- jclass cls = p->env->GetObjectClass(p->progressReporter);
- jmethodID mid = p->env->GetMethodID(cls, "progressReport", "(I)V");
- if (mid != 0) {
- p->env->CallVoidMethod(p->progressReporter, mid, (jint)percent);
+ if (p->mid != 0) {
+ p->env->CallVoidMethod(p->progressReporter, p->mid, (jint)percent);
}
- p->env->DeleteLocalRef(cls);
}
}
Modified: trunk/include/swbuf.h
===================================================================
--- trunk/include/swbuf.h 2019-06-11 01:39:52 UTC (rev 3648)
+++ trunk/include/swbuf.h 2019-06-12 07:01:48 UTC (rev 3649)
@@ -449,6 +449,7 @@
* @return returns true if this buffer starts with the specified prefix
*/
inline bool startsWith(const SWBuf &prefix) const { return !strncmp(c_str(), prefix.c_str(), prefix.size()); }
+ void toUpper();
/**
* @return returns true if this buffer ends with the specified postfix
Modified: trunk/src/modules/swmodule.cpp
===================================================================
--- trunk/src/modules/swmodule.cpp 2019-06-11 01:39:52 UTC (rev 3648)
+++ trunk/src/modules/swmodule.cpp 2019-06-12 07:01:48 UTC (rev 3649)
@@ -592,7 +592,7 @@
// phrase
case -1:
// let's see if we're told to ignore case. If so, then we'll touppstr our term
- if ((flags & REG_ICASE) == REG_ICASE) toupperstr(term);
+ if ((flags & REG_ICASE) == REG_ICASE) term.toUpper();
break;
// multi-word
@@ -609,7 +609,7 @@
}
if ((flags & REG_ICASE) == REG_ICASE) {
for (unsigned int i = 0; i < words.size(); i++) {
- toupperstr(words[i]);
+ words[i].toUpper();
}
}
break;
@@ -705,7 +705,7 @@
// phrase
case -1:
textBuf = stripText();
- if ((flags & REG_ICASE) == REG_ICASE) toupperstr(textBuf);
+ if ((flags & REG_ICASE) == REG_ICASE) textBuf.toUpper();
sres = strstr(textBuf.c_str(), term.c_str());
if (sres) { //it's also in the stripText(), so we have a valid search result item now
*resultKey = *getKey();
@@ -731,7 +731,7 @@
else testBuf.setSize(0);
foundWords = 0;
- if ((flags & REG_ICASE) == REG_ICASE) toupperstr(testBuf.size() ? testBuf : textBuf);
+ if ((flags & REG_ICASE) == REG_ICASE) testBuf.size() ? testBuf.toUpper() : textBuf.toUpper();
for (unsigned int i = 0; i < words.size(); i++) {
sres = strstr(testBuf.size() ? testBuf.c_str() : textBuf.c_str(), words[i].c_str());
if (!sres) {
Modified: trunk/src/utilfuns/swbuf.cpp
===================================================================
--- trunk/src/utilfuns/swbuf.cpp 2019-06-11 01:39:52 UTC (rev 3648)
+++ trunk/src/utilfuns/swbuf.cpp 2019-06-12 07:01:48 UTC (rev 3649)
@@ -26,6 +26,7 @@
#include <stdarg.h>
#include <stdio.h>
+#include <stringmgr.h>
SWORD_NAMESPACE_START
@@ -120,4 +121,7 @@
*end = 0;
}
+
+void SWBuf::toUpper() { assureSize(size()*3); toupperstr(buf, size()*3-1); }
+
SWORD_NAMESPACE_END
More information about the sword-cvs
mailing list