Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: jni/Utils.h

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Patch Set: Removed newly added neetutils code Created April 25, 2014, 9:31 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: jni/Utils.h
diff --git a/jni/Utils.h b/jni/Utils.h
index b011772ee904690c1eb2319634df5a94dc10d6ac..a442e78ea93e201ea180e4b59a14c3e75d574b8a 100644
--- a/jni/Utils.h
+++ b/jni/Utils.h
@@ -130,16 +130,21 @@ inline bool JniGetBooleanField(JNIEnv* env, jclass clazz, jobject jObj, const ch
inline int32_t JniGetIntField(JNIEnv* env, jclass clazz, jobject jObj, const char* name)
{
- return (int32_t)env->GetBooleanField(jObj, env->GetFieldID(clazz, name, "I"));
+ return (int32_t)env->GetIntField(jObj, env->GetFieldID(clazz, name, "I"));
}
inline int64_t JniGetLongField(JNIEnv* env, jclass clazz, jobject jObj, const char* name)
{
- return (int64_t)env->GetBooleanField(jObj, env->GetFieldID(clazz, name, "J"));
+ return (int64_t)env->GetLongField(jObj, env->GetFieldID(clazz, name, "J"));
}
inline jobject NewJniFilter(JNIEnv* env, const AdblockPlus::FilterPtr& filter)
{
+ if (!filter.get())
+ {
+ return 0;
+ }
+
jclass clazz = env->FindClass(PKG("Filter"));
jmethodID method = env->GetMethodID(clazz, "<init>", "(J)V");
return env->NewObject(clazz, method, JniPtrToLong(new AdblockPlus::FilterPtr(filter)));
@@ -147,6 +152,11 @@ inline jobject NewJniFilter(JNIEnv* env, const AdblockPlus::FilterPtr& filter)
inline jobject NewJniSubscription(JNIEnv* env, const AdblockPlus::SubscriptionPtr& subscription)
{
+ if (!subscription.get())
+ {
+ return 0;
+ }
+
jclass clazz = env->FindClass(PKG("Subscription"));
jmethodID method = env->GetMethodID(clazz, "<init>", "(J)V");
return env->NewObject(clazz, method, JniPtrToLong(new AdblockPlus::SubscriptionPtr(subscription)));
@@ -174,16 +184,4 @@ inline jobject NewJniSubscription(JNIEnv* env, const AdblockPlus::SubscriptionPt
return retVal; \
}
-const std::string GetString(JNIEnv *pEnv, jstring str);
-
-template<class T>
-T TrimString(T text)
-{
- // Via http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
- T trimmed(text);
- trimmed.erase(trimmed.begin(), std::find_if(trimmed.begin(), trimmed.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
- trimmed.erase(std::find_if(trimmed.rbegin(), trimmed.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), trimmed.end());
- return trimmed;
-}
-
#endif

Powered by Google App Engine
This is Rietveld