/**
*******************************************************************************
- * Copyright (C) 2007, International Business Machines Corporation, Apple Inc.,*
+ * Copyright (C) 2007,2012 International Business Machines Corporation, Apple Inc.,*
* and others. All Rights Reserved. *
*******************************************************************************
*/
#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 "triedict.h"
#include "aaplbfct.h"
#include "unicode/uscript.h"
#include "unicode/uniset.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
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) {
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
- 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
// 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));
// 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
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
// 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
// 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
// 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 icuDict;
+#endif
+#endif
+ return icuDictMatcher;
}
U_NAMESPACE_END
-#endif /* #if !UCONFIG_NO_BREAK_ITERATION && defined(U_DARWIN) */
+#endif /* #if !UCONFIG_NO_BREAK_ITERATION && U_PLATFORM_IS_DARWIN_BASED */