void utStringUtils::replace( utString &in, const utString &from, const utString &to ) { if ( !from.empty() && from != to ) { // erase if ( to.empty() ) { size_t pos= 0; while ( pos != utString::npos ) { pos= in.find( from ); if ( pos != utString::npos ) in.erase( pos, from.size() ); } } else { size_t pos= 0; while ( pos != utString::npos ) { pos= in.find( from ); if ( pos != utString::npos ) { in.erase( pos, from.size() ); in.insert( pos, to ); } } } } }
const char *platform_getWritablePath() { static utString path; if (path.size()) { return path.c_str(); } const char *tmp = LoomJni::getPackageName(); if (!tmp) { return ""; } // the path is: /data/data/ + package name path = "/data/data/"; if (tmp) { path += tmp; } else { return ""; } return path.c_str(); }
const char *LoomJni::getPackageName() { static utString packageName; if (packageName.size()) { return packageName.c_str(); } loomJniMethodInfo t; if (getStaticMethodInfo(t, "co/theengine/loomdemo/LoomDemo", "getActivityPackageName", "()Ljava/lang/String;")) { jstring str = (jstring)t.getEnv()->CallStaticObjectMethod(t.classID, t.methodID); t.getEnv()->DeleteLocalRef(t.classID); packageName = jstring2string(str); t.getEnv()->DeleteLocalRef(str); lmLog(jniLogGroup, "package name %s", packageName.c_str()); return packageName.c_str(); } return 0; }
// Helper to recognize an asset's type from its path/name. static int loom_asset_recognizeAssetTypeFromPath(utString& path) { // Easy out - empty strings are no good! if (path.length() == 0) { return 0; } // Walk backwards to first dot. size_t firstDotPos = path.size() - 1; for (size_t pos = path.size() - 1; pos > 0; pos--) { if (path.at(pos) != '.') { continue; } firstDotPos = pos; break; } // Split out the extension. utString pathExt = path.substr(firstDotPos + 1); // See if we can get a type out of any of the recognizers. int type = 0; for (UTsize i = 0; i < gRecognizerList.size(); i++) { type = gRecognizerList[i](pathExt.c_str()); if (type) { break; } } // No match, so let's use text. if (type == 0) { lmLogInfo(gAssetLogGroup, "Couldn't recognize '%s', defaulting to LATText...", path.c_str()); type = LATText; } return type; }
const char *platform_getSettingsPath() { static utString path; if (path.size()) { return path.c_str(); } path = LoomJni::getSettingsPath(); return path.c_str(); }