]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/aaplbfct.cpp
ICU-62108.0.1.tar.gz
[apple/icu.git] / icuSources / common / aaplbfct.cpp
index e77a3105ad8167d279055b1032828d03c7053f2e..8d53b09196095b2155a668c64f7ae22fde3fc9e3 100644 (file)
@@ -1,6 +1,6 @@
 /**
  *******************************************************************************
 /**
  *******************************************************************************
- * Copyright (C) 2007, International Business Machines Corporation, Apple Inc.,*
+ * Copyright (C) 2007,2012 International Business Machines Corporation, Apple Inc.,*
  * and others.  All Rights Reserved.                                           *
  *******************************************************************************
  */
  * and others.  All Rights Reserved.                                           *
  *******************************************************************************
  */
@@ -8,11 +8,10 @@
 #define __STDC_LIMIT_MACROS 1
 #include "unicode/utypes.h"
 
 #define __STDC_LIMIT_MACROS 1
 #include "unicode/utypes.h"
 
-#if !UCONFIG_NO_BREAK_ITERATION && defined(U_DARWIN)
+#if !UCONFIG_NO_BREAK_ITERATION && U_PLATFORM_IS_DARWIN_BASED
 
 #include "brkeng.h"
 #include "dictbe.h"
 
 #include "brkeng.h"
 #include "dictbe.h"
-#include "triedict.h"
 #include "aaplbfct.h"
 #include "unicode/uscript.h"
 #include "unicode/uniset.h"
 #include "aaplbfct.h"
 #include "unicode/uscript.h"
 #include "unicode/uniset.h"
@@ -30,6 +29,9 @@
 #include <time.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <time.h>
 #include <stdio.h>
 #include <stdint.h>
+// The following is now already included by platform.h (included indirectly by
+// utypes.h) if U_PLATFORM_IS_DARWIN_BASED but it doesn't hurt to re-include here
+#include <TargetConditionals.h>
 
 U_NAMESPACE_BEGIN
 
 
 U_NAMESPACE_BEGIN
 
@@ -45,6 +47,10 @@ AppleLanguageBreakFactory::AppleLanguageBreakFactory(UErrorCode &status)
 AppleLanguageBreakFactory::~AppleLanguageBreakFactory() {
 }
 
 AppleLanguageBreakFactory::~AppleLanguageBreakFactory() {
 }
 
+#if !TARGET_OS_EMBEDDED
+#if 0
+// need to update loadDictionaryMatcherFor implementation below
+
 // Helper function that makes a length-delimited buffer look NUL-terminated
 static __attribute__((always_inline)) inline UChar nextUChar(const UChar *&p, ptrdiff_t &l) {
        if (l > 0) {
 // Helper function that makes a length-delimited buffer look NUL-terminated
 static __attribute__((always_inline)) inline UChar nextUChar(const UChar *&p, ptrdiff_t &l) {
        if (l > 0) {
@@ -176,11 +182,26 @@ static void addDictFile(MutableTrieDictionary *to, const char *path) {
        static const char       sArchType[] = ".le";    // little endian
 #endif
 
        static const char       sArchType[] = ".le";    // little endian
 #endif
 
-const CompactTrieDictionary *
-AppleLanguageBreakFactory::loadDictionaryFor(UScriptCode script, int32_t breakType) {
-       const CompactTrieDictionary *icuDict = ICULanguageBreakFactory::loadDictionaryFor(script, breakType);
+#endif
+#endif
+
+/*
+In ICU50,
+ICULanguageBreakFactory changes from 
+  virtual const CompactTrieDictionary *loadDictionaryFor(UScriptCode script, int32_t breakType);
+to
+  virtual DictionaryMatcher *loadDictionaryMatcherFor(UScriptCode script, int32_t breakType);
+and CompactTrieDictionary no longer exists. Need to work out  new implementation below.
+*/
+
+DictionaryMatcher *
+AppleLanguageBreakFactory::loadDictionaryMatcherFor(UScriptCode script, int32_t breakType) {
+       DictionaryMatcher *icuDictMatcher = ICULanguageBreakFactory::loadDictionaryMatcherFor(script);
+#if !TARGET_OS_EMBEDDED
+#if 0
+// need to update loadDictionaryMatcherFor implementation below
        // We only look for a user dictionary if there is actually an ICU dictionary
        // We only look for a user dictionary if there is actually an ICU dictionary
-       if (icuDict != NULL) {
+       if (icuDictMatcher != NULL) {
                UErrorCode status = U_ZERO_ERROR;
                const char *scriptName = uscript_getName(script);
                char path[256];                 // PATH_MAX is overkill in this case
                UErrorCode status = U_ZERO_ERROR;
                const char *scriptName = uscript_getName(script);
                char path[256];                 // PATH_MAX is overkill in this case
@@ -196,7 +217,7 @@ AppleLanguageBreakFactory::loadDictionaryFor(UScriptCode script, int32_t breakTy
                
                // Iterate the dictionary directories and accumulate in dirGlob
                NSSearchPathEnumerationState state = NSStartSearchPathEnumeration(NSLibraryDirectory, (NSSearchPathDomainMask) (NSUserDomainMask|NSLocalDomainMask|NSNetworkDomainMask));
                
                // Iterate the dictionary directories and accumulate in dirGlob
                NSSearchPathEnumerationState state = NSStartSearchPathEnumeration(NSLibraryDirectory, (NSSearchPathDomainMask) (NSUserDomainMask|NSLocalDomainMask|NSNetworkDomainMask));
-               while (state = NSGetNextSearchPathEnumeration(state, path)) {
+               while ((state = NSGetNextSearchPathEnumeration(state, path)) != 0) {
                        // First get the directory itself. We should never overflow, but use strlcat anyway
                        // to avoid a crash if we do.
                        strlcat(path, "/Dictionaries", sizeof(path));
                        // First get the directory itself. We should never overflow, but use strlcat anyway
                        // to avoid a crash if we do.
                        strlcat(path, "/Dictionaries", sizeof(path));
@@ -210,7 +231,7 @@ AppleLanguageBreakFactory::loadDictionaryFor(UScriptCode script, int32_t breakTy
                // TODO: Delete the cache?
                if (dirGlob.gl_pathc == 0) {
                        globfree(&dirGlob);
                // TODO: Delete the cache?
                if (dirGlob.gl_pathc == 0) {
                        globfree(&dirGlob);
-                       return icuDict;
+                       return icuDictMatcher;
                }
                
                // See if there is a cache file already; get its mod time
                }
                
                // See if there is a cache file already; get its mod time
@@ -228,7 +249,7 @@ AppleLanguageBreakFactory::loadDictionaryFor(UScriptCode script, int32_t breakTy
                globFlags &= ~GLOB_APPEND;
                char **pathsp = dirGlob.gl_pathv;
                const char *dictpath;
                globFlags &= ~GLOB_APPEND;
                char **pathsp = dirGlob.gl_pathv;
                const char *dictpath;
-               while (dictpath = *pathsp++) {
+               while ((dictpath = *pathsp++) != NULL) {
                        // Stat the directory -- ignore if stat failure
                        if (!stat(dictpath, &dictStat)) {
                                // Glob the dictionaries in the directory
                        // Stat the directory -- ignore if stat failure
                        if (!stat(dictpath, &dictStat)) {
                                // Glob the dictionaries in the directory
@@ -251,7 +272,7 @@ AppleLanguageBreakFactory::loadDictionaryFor(UScriptCode script, int32_t breakTy
                // TODO: Delete the cache?
                if (fileGlob.gl_pathc == 0) {
                        globfree(&fileGlob);
                // TODO: Delete the cache?
                if (fileGlob.gl_pathc == 0) {
                        globfree(&fileGlob);
-                       return icuDict;
+                       return icuDictMatcher;
                }
                
                // Now compare the last modified stamp for the cache against all the dictionaries
                }
                
                // Now compare the last modified stamp for the cache against all the dictionaries
@@ -266,7 +287,7 @@ AppleLanguageBreakFactory::loadDictionaryFor(UScriptCode script, int32_t breakTy
                // Do we need to build the dictionary cache?
                if (!cacheGood) {
                        // Create a mutable dictionary from the ICU dictionary
                // Do we need to build the dictionary cache?
                if (!cacheGood) {
                        // Create a mutable dictionary from the ICU dictionary
-                       MutableTrieDictionary *sum = icuDict->cloneMutable(status);
+                       MutableTrieDictionary *sum = icuDictMatcher->cloneMutable(status);
                        pathsp = fileGlob.gl_pathv;
                        while (U_SUCCESS(status) && (dictpath = *pathsp++)) {
                                // Add the contents of a file to the sum
                        pathsp = fileGlob.gl_pathv;
                        while (U_SUCCESS(status) && (dictpath = *pathsp++)) {
                                // Add the contents of a file to the sum
@@ -352,16 +373,18 @@ AppleLanguageBreakFactory::loadDictionaryFor(UScriptCode script, int32_t breakTy
                
                // If we were successful, free the ICU dictionary and return ours
                if (U_SUCCESS(status)) {
                
                // If we were successful, free the ICU dictionary and return ours
                if (U_SUCCESS(status)) {
-                       delete icuDict;
+                       delete icuDictMatcher;
                        return cacheDict;
                }
                else {
                        delete cacheDict;
                }
        }
                        return cacheDict;
                }
                else {
                        delete cacheDict;
                }
        }
-       return icuDict;
+#endif
+#endif
+       return icuDictMatcher;
 }
 
 U_NAMESPACE_END
 
 }
 
 U_NAMESPACE_END
 
-#endif /* #if !UCONFIG_NO_BREAK_ITERATION && defined(U_DARWIN) */
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION && U_PLATFORM_IS_DARWIN_BASED */