aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp
diff options
context:
space:
mode:
authorKeisuke Kuroyanagi <ksk@google.com>2013-11-20 05:35:15 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-11-20 05:35:16 +0000
commit15c8b84af87441fdd10b239f0a565b0ce6ffb533 (patch)
tree52f4c35d4e743741912d9da77d9380c3d1df81c8 /native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp
parent994530d9bdc7684cc4501b0ced567ae1b393c2e8 (diff)
parentdc14d5fbba553c39929539ca8a71f534383d7e0a (diff)
downloadlatinime-15c8b84af87441fdd10b239f0a565b0ce6ffb533.tar.gz
latinime-15c8b84af87441fdd10b239f0a565b0ce6ffb533.tar.xz
latinime-15c8b84af87441fdd10b239f0a565b0ce6ffb533.zip
Merge "Implement Ver4PatriciaTriePolicy::flush()."
Diffstat (limited to 'native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp')
-rw-r--r--native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp b/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp
index 1748d5a49..dedcd7a99 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/utils/file_utils.cpp
@@ -88,4 +88,43 @@ namespace latinime {
snprintf(outFilePath, filePathBufSize, "%s/%s", dirPath, fileName);
}
+/* static */ bool FileUtils::getFilePathWithoutSuffix(const char *const filePath,
+ const char *const suffix, const int outDirPathBufSize, char *const outDirPath) {
+ const int filePathLength = strlen(filePath);
+ const int suffixLength = strlen(suffix);
+ if (filePathLength <= suffixLength) {
+ AKLOGE("File path length (%s:%d) is shorter that suffix length (%s:%d).",
+ filePath, filePathLength, suffix, suffixLength);
+ return false;
+ }
+ const int resultFilePathLength = filePathLength - suffixLength;
+ if (outDirPathBufSize <= resultFilePathLength) {
+ AKLOGE("outDirPathBufSize is too small. filePath: %s, suffix: %s, outDirPathBufSize: %d",
+ filePath, suffix, outDirPathBufSize);
+ return false;
+ }
+ if (strncmp(filePath + resultFilePathLength, suffix, suffixLength) != 0) {
+ AKLOGE("File Path %s does not have %s as a suffix", filePath, suffix);
+ return false;
+ }
+ snprintf(outDirPath, resultFilePathLength + 1 /* terminator */, "%s", filePath);
+ return true;
+}
+
+/* static */ void FileUtils::getDirPath(const char *const filePath, const int outDirPathBufSize,
+ char *const outDirPath) {
+ for (int i = strlen(filePath) - 1; i >= 0; --i) {
+ if (filePath[i] == '/') {
+ if (i >= outDirPathBufSize) {
+ AKLOGE("outDirPathBufSize is too small. filePath: %s, outDirPathBufSize: %d",
+ filePath, outDirPathBufSize);
+ ASSERT(false);
+ return;
+ }
+ snprintf(outDirPath, i + 1 /* terminator */, "%s", filePath);
+ return;
+ }
+ }
+}
+
} // namespace latinime