8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 06:03:02 +01:00
This commit is contained in:
robocop 2008-02-26 07:23:32 +00:00
parent 62a00ef37b
commit ac9836f499
14 changed files with 115 additions and 118 deletions

View File

@ -197,11 +197,9 @@ INTL_BOOL CVBIG5_check_big5(charset* cs,
*offending_position = big5_str - big5_str_start; *offending_position = big5_str - big5_str_start;
return (false); return (false);
} }
else {
big5_str += 2; big5_str += 2;
big5_len -= 1; big5_len -= 1;
} }
}
else { /* it is a ASCII */ else { /* it is a ASCII */
big5_str++; big5_str++;

View File

@ -559,11 +559,9 @@ static USHORT CVJIS_check_euc(const UCHAR* euc_str, USHORT euc_len)
if (euc_len == 0) { /* truncated kanji */ if (euc_len == 0) { /* truncated kanji */
return (1); return (1);
} }
else {
euc_str += 2; euc_str += 2;
euc_len -= 1; euc_len -= 1;
} }
}
else { /* it is a ASCII */ else { /* it is a ASCII */
euc_str++; euc_str++;
} }
@ -595,11 +593,9 @@ static USHORT CVJIS_check_sjis(const UCHAR* sjis_str, USHORT sjis_len)
if (sjis_len == 0) { /* truncated KANJI */ if (sjis_len == 0) { /* truncated KANJI */
return (1); return (1);
} }
else {
sjis_str += 2; sjis_str += 2;
sjis_len -= 1; sjis_len -= 1;
} }
}
else { /*It is a KANA */ else { /*It is a KANA */
sjis_str++; sjis_str++;
} }

View File

@ -189,11 +189,9 @@ INTL_BOOL CVKSC_check_ksc(charset* cs,
*offending_position = ksc_str - ksc_str_start; *offending_position = ksc_str - ksc_str_start;
return (false); return (false);
} }
else {
ksc_str += 2; ksc_str += 2;
ksc_len -= 1; ksc_len -= 1;
} }
}
else if (c1 > 0x7f) /* error */ else if (c1 > 0x7f) /* error */
{ {
if (offending_position) if (offending_position)

View File

@ -71,11 +71,9 @@ USHORT KANJI_check_euc(const UCHAR* euc_str, USHORT euc_len)
if (euc_len == 0) { /* truncated kanji */ if (euc_len == 0) { /* truncated kanji */
return (1); return (1);
} }
else {
euc_str += 2; euc_str += 2;
euc_len -= 1; euc_len -= 1;
} }
}
else { /* it is a ASCII */ else { /* it is a ASCII */
euc_str++; euc_str++;
} }
@ -105,11 +103,9 @@ USHORT KANJI_check_sjis(const UCHAR* sjis_str, USHORT sjis_len)
if (sjis_len == 0) { /* truncated KANJI */ if (sjis_len == 0) { /* truncated KANJI */
return (1); return (1);
} }
else {
sjis_str += 2; sjis_str += 2;
sjis_len -= 1; sjis_len -= 1;
} }
}
else { /*It is a KANA */ else { /*It is a KANA */
sjis_str++; sjis_str++;
} }

View File

@ -561,13 +561,13 @@ SSHORT famasc_compare(texttype* obj, ULONG l1, const BYTE* s1, ULONG l2, const B
for (ULONG i = 0; i < len; i++) { for (ULONG i = 0; i < len; i++) {
if (s1[i] == s2[i]) if (s1[i] == s2[i])
continue; continue;
else if (all_spaces(&s1[i], (SLONG) (l1 - i))) if (all_spaces(&s1[i], (SLONG) (l1 - i)))
return -1; return -1;
else if (all_spaces(&s2[i], (SLONG) (l2 - i))) if (all_spaces(&s2[i], (SLONG) (l2 - i)))
return 1; return 1;
else if (s1[i] < s2[i]) if (s1[i] < s2[i])
return -1; return -1;
else
return 1; return 1;
} }

View File

@ -150,12 +150,12 @@ bool LCICU_texttype_init(texttype* tt,
tt, name, charSetName, attributes, tt, name, charSetName, attributes,
specificAttributes, specificAttributesLength, configInfo); specificAttributes, specificAttributesLength, configInfo);
} }
else if (len > 8 && strcmp(name + len - 8, "_UNICODE") == 0) if (len > 8 && strcmp(name + len - 8, "_UNICODE") == 0)
{ {
return texttype_unicode_init( return texttype_unicode_init(
tt, name, charSetName, attributes, tt, name, charSetName, attributes,
specificAttributes, specificAttributesLength, configInfo); specificAttributes, specificAttributesLength, configInfo);
} }
else
return false; return false;
} }

View File

@ -65,7 +65,7 @@ TEXTTYPE_ENTRY(JIS220_init)
//cache->texttype_fn_str_to_lower = sjis_str_to_lower; //cache->texttype_fn_str_to_lower = sjis_str_to_lower;
return true; return true;
} }
else
return false; return false;
} }
@ -80,7 +80,7 @@ TEXTTYPE_ENTRY(JIS230_init)
//cache->texttype_fn_str_to_lower = famasc_str_to_lower; //cache->texttype_fn_str_to_lower = famasc_str_to_lower;
return true; return true;
} }
else
return false; return false;
} }

View File

@ -78,7 +78,7 @@ TEXTTYPE_ENTRY(ksc_5601_dict_init)
cache->texttype_fn_compare = LCKSC_compare; cache->texttype_fn_compare = LCKSC_compare;
return true; return true;
} }
else
return false; return false;
} }
@ -267,15 +267,15 @@ static SSHORT LCKSC_compare(texttype* obj, ULONG l1, const BYTE* s1, ULONG l2, c
for (ULONG i = 0; i < len; i++) { for (ULONG i = 0; i < len; i++) {
if (key1[i] == key2[i]) if (key1[i] == key2[i])
continue; continue;
else if (key1[i] < key2[i]) if (key1[i] < key2[i])
return -1; return -1;
else
return 1; return 1;
} }
if (len1 < len2) if (len1 < len2)
return -1; return -1;
else if (len1 > len2) if (len1 > len2)
return 1; return 1;
else
return 0; return 0;
} }

View File

@ -310,8 +310,10 @@ USHORT LC_NARROW_string_to_key(texttype* obj, USHORT iInLen, const BYTE* pInChar
iOutLen -= lprimary; iOutLen -= lprimary;
if (key_type == INTL_KEY_PARTIAL) if (key_type == INTL_KEY_PARTIAL)
{
/* return length of key */ /* return length of key */
return (outbuff - pOutChar); return (outbuff - pOutChar);
}
bool useLevel = !(obj->texttype_impl->texttype_flags & TEXTTYPE_secondary_insensitive); bool useLevel = !(obj->texttype_impl->texttype_flags & TEXTTYPE_secondary_insensitive);
@ -492,8 +494,7 @@ static const SortOrderTblEntry* get_coltab_entry(texttype* obj, const UCHAR** p,
(*p)++; (*p)++;
return col; return col;
} }
else
{
/* Both flags set indicate a special value */ /* Both flags set indicate a special value */
/* Need a new col */ /* Need a new col */
(*l)--; (*l)--;
@ -501,8 +502,8 @@ static const SortOrderTblEntry* get_coltab_entry(texttype* obj, const UCHAR** p,
stat->stat_flags |= LC_HAVE_SPECIAL; stat->stat_flags |= LC_HAVE_SPECIAL;
continue; continue;
} }
}
else if (!((col->IsExpand && !(obj->texttype_impl->texttype_flags & TEXTTYPE_disable_expansions)) || if (!((col->IsExpand && !(obj->texttype_impl->texttype_flags & TEXTTYPE_disable_expansions)) ||
(col->IsCompress && !(obj->texttype_impl->texttype_flags & TEXTTYPE_disable_compressions)))) (col->IsCompress && !(obj->texttype_impl->texttype_flags & TEXTTYPE_disable_compressions))))
{ {
/* Have col */ /* Have col */
@ -510,7 +511,8 @@ static const SortOrderTblEntry* get_coltab_entry(texttype* obj, const UCHAR** p,
(*p)++; (*p)++;
return col; return col;
} }
else if (col->IsExpand) {
if (col->IsExpand) {
const ExpandChar* exp = &((const ExpandChar*) obj->texttype_impl->texttype_expand_table)[0]; const ExpandChar* exp = &((const ExpandChar*) obj->texttype_impl->texttype_expand_table)[0];
while (exp->Ch && exp->Ch != **p) while (exp->Ch && exp->Ch != **p)
exp++; exp++;
@ -524,7 +526,8 @@ static const SortOrderTblEntry* get_coltab_entry(texttype* obj, const UCHAR** p,
stat->stat_flags |= LC_HAVE_WAITING; stat->stat_flags |= LC_HAVE_WAITING;
return col; return col;
} }
else { /* (col->IsCompress) */
/* (col->IsCompress) */
if (*l > 1) { if (*l > 1) {
const CompressPair* cmp = const CompressPair* cmp =
&((const CompressPair*) obj->texttype_impl-> &((const CompressPair*) obj->texttype_impl->
@ -547,7 +550,6 @@ static const SortOrderTblEntry* get_coltab_entry(texttype* obj, const UCHAR** p,
(*p)++; (*p)++;
return col; return col;
} }
}
return NULL; return NULL;
} }
@ -687,15 +689,16 @@ static SSHORT old_fam2_compare(texttype* obj, ULONG l1, const BYTE* s1,
for (ULONG i = 0; i < len; i++) { for (ULONG i = 0; i < len; i++) {
if (key1[i] == key2[i]) if (key1[i] == key2[i])
continue; continue;
else if (key1[i] < key2[i]) if (key1[i] < key2[i])
return (-1); return (-1);
else
return (1); return (1);
} }
if (len1 < len2) if (len1 < len2)
return (-1); return (-1);
else if (len1 > len2) if (len1 > len2)
return (1); return (1);
return (0); return (0);
} }
#endif /* DEBUG_COMPARE */ #endif /* DEBUG_COMPARE */
@ -1014,7 +1017,7 @@ bool LC_NARROW_family3(
return true; return true;
} }
else
return false; return false;
} }

View File

@ -528,7 +528,7 @@ INTL_BOOL FB_DLL_EXPORT LD_lookup_texttype(texttype* tt, const ASCII* texttype_n
{ {
if (LD_lookup_charset(&cs, charset_name, configInfo)) if (LD_lookup_charset(&cs, charset_name, configInfo))
break; break;
else
return false; return false;
} }
} }
@ -572,12 +572,13 @@ ULONG FB_DLL_EXPORT LD_setup_attributes(
if (dstLen == 0) if (dstLen == 0)
return newSpecificAttributes.length(); return newSpecificAttributes.length();
else if (newSpecificAttributes.length() <= dstLen)
if (newSpecificAttributes.length() <= dstLen)
{ {
memcpy(dst, newSpecificAttributes.begin(), newSpecificAttributes.length()); memcpy(dst, newSpecificAttributes.begin(), newSpecificAttributes.length());
return newSpecificAttributes.length(); return newSpecificAttributes.length();
} }
else
return INTL_BAD_STR_LENGTH; return INTL_BAD_STR_LENGTH;
} }

View File

@ -108,8 +108,7 @@ int main()
for (i = 0; i <= 255; i++) { for (i = 0; i <= 255; i++) {
if (from_unicode_map[i] + 0xFF >= sizeof(from_unicode_mapping_array)) { if (from_unicode_map[i] + 0xFF >= sizeof(from_unicode_mapping_array)) {
printf("From_unicode array bounds error at position %02x00\n", printf("From_unicode array bounds error at position %02x00\n", i);
i);
continue; continue;
} }

View File

@ -1771,19 +1771,19 @@ static sort_record* get_merge(merge_control* merge, sort_context* scb
} }
if (!merge->mrg_record_b) if (!merge->mrg_record_b)
{
if (merge->mrg_stream_b) { if (merge->mrg_stream_b) {
merge = (merge_control*) merge->mrg_stream_b; merge = (merge_control*) merge->mrg_stream_b;
continue;
} }
else if ( (record = merge->mrg_record_a) ) { else if ( (record = merge->mrg_record_a) ) {
merge->mrg_record_a = NULL; merge->mrg_record_a = NULL;
merge = merge->mrg_header.rmh_parent; merge = merge->mrg_header.rmh_parent;
continue;
} }
else { else {
eof = true; eof = true;
record = (sort_record*) - 1; record = (sort_record*) - 1;
merge = merge->mrg_header.rmh_parent; merge = merge->mrg_header.rmh_parent;
}
continue; continue;
} }

View File

@ -195,7 +195,7 @@ USHORT UnicodeUtil::utf16ToKey(USHORT srcLen, const USHORT* src, USHORT dstLen,
UConverter* conv = ucnv_open("BOCU-1", &status); UConverter* conv = ucnv_open("BOCU-1", &status);
fb_assert(U_SUCCESS(status)); fb_assert(U_SUCCESS(status));
int32_t len = ucnv_fromUChars(conv, reinterpret_cast<char*>(dst), dstLen, const int32_t len = ucnv_fromUChars(conv, reinterpret_cast<char*>(dst), dstLen,
// safe cast - alignment not changed // safe cast - alignment not changed
reinterpret_cast<const UChar*>(src), srcLen / sizeof(*src), &status); reinterpret_cast<const UChar*>(src), srcLen / sizeof(*src), &status);
fb_assert(U_SUCCESS(status)); fb_assert(U_SUCCESS(status));
@ -493,10 +493,10 @@ ULONG UnicodeUtil::utf16ToUtf32(ULONG srcLen, const USHORT* src, ULONG dstLen, U
while (src < srcEnd && dst < dstEnd) while (src < srcEnd && dst < dstEnd)
{ {
ULONG ch = *src++; ULONG ch = *src++;
ULONG ch2;
if (UTF_IS_LEAD(ch)) if (UTF_IS_LEAD(ch))
{ {
ULONG ch2;
if (src < srcEnd && UTF_IS_TRAIL(ch2 = *src)) if (src < srcEnd && UTF_IS_TRAIL(ch2 = *src))
{ {
ch = UTF16_GET_PAIR_VALUE(ch, ch2); ch = UTF16_GET_PAIR_VALUE(ch, ch2);
@ -543,7 +543,7 @@ ULONG UnicodeUtil::utf32ToUtf16(ULONG srcLen, const ULONG* src, ULONG dstLen, US
while (src < srcEnd && dst < dstEnd) while (src < srcEnd && dst < dstEnd)
{ {
ULONG ch = *src++; const ULONG ch = *src++;
if (ch <= 0xFFFF) if (ch <= 0xFFFF)
*(dst++) = ch; *(dst++) = ch;
@ -621,7 +621,7 @@ ULONG UnicodeUtil::utf16Substring(ULONG srcLen, const USHORT* src, ULONG dstLen,
while (src < srcEnd && dst < dstEnd && pos < startPos) while (src < srcEnd && dst < dstEnd && pos < startPos)
{ {
ULONG ch = *src++; const ULONG ch = *src++;
if (UTF_IS_LEAD(ch)) if (UTF_IS_LEAD(ch))
{ {
@ -634,13 +634,13 @@ ULONG UnicodeUtil::utf16Substring(ULONG srcLen, const USHORT* src, ULONG dstLen,
while (src < srcEnd && dst < dstEnd && pos < startPos + length) while (src < srcEnd && dst < dstEnd && pos < startPos + length)
{ {
ULONG ch = *src++; const ULONG ch = *src++;
ULONG ch2;
*(dst++) = ch; *(dst++) = ch;
if (UTF_IS_LEAD(ch)) if (UTF_IS_LEAD(ch))
{ {
ULONG ch2;
if (src < srcEnd && UTF_IS_TRAIL(ch2 = *src)) if (src < srcEnd && UTF_IS_TRAIL(ch2 = *src))
{ {
*(dst++) = ch2; *(dst++) = ch2;
@ -665,7 +665,7 @@ INTL_BOOL UnicodeUtil::utf8WellFormed(ULONG len, const UCHAR* str, ULONG* offend
if (c > 0x7F) if (c > 0x7F)
{ {
ULONG save_i = i - 1; const ULONG save_i = i - 1;
c = utf8_nextCharSafeBody(str, reinterpret_cast<int32_t*>(&i), len, c, -1); c = utf8_nextCharSafeBody(str, reinterpret_cast<int32_t*>(&i), len, c, -1);
@ -691,7 +691,7 @@ INTL_BOOL UnicodeUtil::utf16WellFormed(ULONG len, const USHORT* str, ULONG* offe
for (ULONG i = 0; i < len;) for (ULONG i = 0; i < len;)
{ {
ULONG save_i = i; const ULONG save_i = i;
uint32_t c; uint32_t c;
U16_NEXT(str, i, len, c); U16_NEXT(str, i, len, c);
@ -898,7 +898,7 @@ UnicodeUtil::ICU* UnicodeUtil::loadICU(const Firebird::string& icuVersion,
WriteLockGuard writeGuard(icuModules->lock); WriteLockGuard writeGuard(icuModules->lock);
// In this small amount of time, one may already loaded the // In this small amount of time, one may already loaded the
// same version, so withing the write lock we verify again. // same version, so within the write lock we verify again.
ICU* icu2; ICU* icu2;
if (icuModules->modules().get(version, icu2)) if (icuModules->modules().get(version, icu2))
{ {
@ -938,12 +938,13 @@ UnicodeUtil::Utf16Collation* UnicodeUtil::Utf16Collation::create(
Firebird::IntlUtil::SpecificAttributesMap& specificAttributes, const Firebird::string& configInfo) Firebird::IntlUtil::SpecificAttributesMap& specificAttributes, const Firebird::string& configInfo)
{ {
string locale; string locale;
string collVersion;
int attributeCount = 0; int attributeCount = 0;
bool error; bool error;
if (specificAttributes.get(IntlUtil::convertAsciiToUtf16("LOCALE"), locale)) if (specificAttributes.get(IntlUtil::convertAsciiToUtf16("LOCALE"), locale))
++attributeCount; ++attributeCount;
string collVersion;
if (specificAttributes.get(IntlUtil::convertAsciiToUtf16("COLL-VERSION"), collVersion)) if (specificAttributes.get(IntlUtil::convertAsciiToUtf16("COLL-VERSION"), collVersion))
{ {
++attributeCount; ++attributeCount;
@ -1015,6 +1016,7 @@ UnicodeUtil::Utf16Collation* UnicodeUtil::Utf16Collation::create(
tt->texttype_flags = TEXTTYPE_DIRECT_MATCH; tt->texttype_flags = TEXTTYPE_DIRECT_MATCH;
USet* contractions = icu->usetOpen(0, 0); USet* contractions = icu->usetOpen(0, 0);
// status not verified here.
icu->ucolGetContractions(partialCollator, contractions, &status); icu->ucolGetContractions(partialCollator, contractions, &status);
Utf16Collation* obj = new Utf16Collation(); Utf16Collation* obj = new Utf16Collation();
@ -1033,11 +1035,11 @@ UnicodeUtil::Utf16Collation* UnicodeUtil::Utf16Collation::create(
UnicodeUtil::Utf16Collation::~Utf16Collation() UnicodeUtil::Utf16Collation::~Utf16Collation()
{ {
icu->usetClose(static_cast<USet*>(contractions)); icu->usetClose(contractions);
icu->ucolClose((UCollator*)compareCollator); icu->ucolClose(compareCollator);
icu->ucolClose((UCollator*)partialCollator); icu->ucolClose(partialCollator);
icu->ucolClose((UCollator*)sortCollator); icu->ucolClose(sortCollator);
// ASF: we should not "delete icu" // ASF: we should not "delete icu"
} }
@ -1077,7 +1079,7 @@ USHORT UnicodeUtil::Utf16Collation::stringToKey(USHORT srcLen, const USHORT* src
srcLen = pad - src + 1; srcLen = pad - src + 1;
} }
void* coll; const UCollator* coll = 0;
switch (key_type) switch (key_type)
{ {
@ -1091,7 +1093,7 @@ USHORT UnicodeUtil::Utf16Collation::stringToKey(USHORT srcLen, const USHORT* src
{ {
UChar str[10]; UChar str[10];
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
int len = icu->usetGetItem(static_cast<USet*>(contractions), int len = icu->usetGetItem(contractions,
i, NULL, NULL, str, sizeof(str), &status); i, NULL, NULL, str, sizeof(str), &status);
if (len > srcLen) if (len > srcLen)
@ -1126,7 +1128,7 @@ USHORT UnicodeUtil::Utf16Collation::stringToKey(USHORT srcLen, const USHORT* src
if (srcLen == 0) if (srcLen == 0)
return 0; return 0;
return icu->ucolGetSortKey(static_cast<const UCollator*>(coll), return icu->ucolGetSortKey(coll,
reinterpret_cast<const UChar*>(src), srcLen, dst, dstLen); reinterpret_cast<const UChar*>(src), srcLen, dst, dstLen);
} }
@ -1165,7 +1167,7 @@ SSHORT UnicodeUtil::Utf16Collation::compare(ULONG len1, const USHORT* str1,
len2 = pad - str2 + 1; len2 = pad - str2 + 1;
} }
return (SSHORT)icu->ucolStrColl(static_cast<const UCollator*>(compareCollator), return (SSHORT)icu->ucolStrColl(compareCollator,
// safe casts - alignment not changed // safe casts - alignment not changed
reinterpret_cast<const UChar*>(str1), len1, reinterpret_cast<const UChar*>(str1), len1,
reinterpret_cast<const UChar*>(str2), len2); reinterpret_cast<const UChar*>(str2), len2);
@ -1175,9 +1177,6 @@ SSHORT UnicodeUtil::Utf16Collation::compare(ULONG len1, const USHORT* str1,
ULONG UnicodeUtil::Utf16Collation::canonical(ULONG srcLen, const USHORT* src, ULONG dstLen, ULONG* dst, ULONG UnicodeUtil::Utf16Collation::canonical(ULONG srcLen, const USHORT* src, ULONG dstLen, ULONG* dst,
const ULONG* exceptions) const ULONG* exceptions)
{ {
USHORT errCode;
ULONG errPosition;
HalfStaticArray<USHORT, BUFFER_SMALL / 2> upperStr; HalfStaticArray<USHORT, BUFFER_SMALL / 2> upperStr;
if ((attributes & (TEXTTYPE_ATTR_CASE_INSENSITIVE | TEXTTYPE_ATTR_ACCENT_INSENSITIVE)) == if ((attributes & (TEXTTYPE_ATTR_CASE_INSENSITIVE | TEXTTYPE_ATTR_ACCENT_INSENSITIVE)) ==
@ -1193,7 +1192,7 @@ ULONG UnicodeUtil::Utf16Collation::canonical(ULONG srcLen, const USHORT* src, UL
if (errorCode <= 0) if (errorCode <= 0)
{ {
int32_t capacity = dstLen; const int32_t capacity = dstLen;
int32_t len = srcLen / sizeof(USHORT); int32_t len = srcLen / sizeof(USHORT);
int32_t limit = len; int32_t limit = len;
@ -1219,6 +1218,8 @@ ULONG UnicodeUtil::Utf16Collation::canonical(ULONG srcLen, const USHORT* src, UL
} }
// convert UTF-16 to UTF-32 // convert UTF-16 to UTF-32
USHORT errCode;
ULONG errPosition;
return utf16ToUtf32(srcLen, src, dstLen, dst, &errCode, &errPosition) / sizeof(ULONG); return utf16ToUtf32(srcLen, src, dstLen, dst, &errCode, &errPosition) / sizeof(ULONG);
} }
@ -1236,7 +1237,7 @@ UnicodeUtil::ICU* UnicodeUtil::Utf16Collation::loadICU(
if (!icu) if (!icu)
continue; continue;
UErrorCode status = U_ZERO_ERROR; //UErrorCode status = U_ZERO_ERROR;
if (locale.hasData()) if (locale.hasData())
{ {

View File

@ -30,6 +30,11 @@
#include "intlobj_new.h" #include "intlobj_new.h"
#include "../jrd/IntlUtil.h" #include "../jrd/IntlUtil.h"
#include "../jrd/os/mod_loader.h" #include "../jrd/os/mod_loader.h"
//#include "unicode/ucol.h"
//#include "unicode/ucnv.h"
struct UCollator;
struct USet;
namespace Jrd { namespace Jrd {
@ -93,10 +98,10 @@ public:
ICU* icu; ICU* icu;
texttype* tt; texttype* tt;
USHORT attributes; USHORT attributes;
void* compareCollator; UCollator* compareCollator;
void* partialCollator; UCollator* partialCollator;
void* sortCollator; UCollator* sortCollator;
void* contractions; USet* contractions;
int contractionsCount; int contractionsCount;
}; };