MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / compare

Method compare

src/common/TextType.cpp:247–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245
246
247SSHORT TextType::compare(ULONG len1, const UCHAR* str1, ULONG len2, const UCHAR* str2)
248{
249 INTL_BOOL error = false;
250
251 if (tt->texttype_fn_compare)
252 return (*tt->texttype_fn_compare)(tt, len1, str1, len2, str2, &error);
253
254 const UCHAR* space = getCharSet()->getSpace();
255 BYTE spaceLength = getCharSet()->getSpaceLength();
256 Firebird::HalfStaticArray<UCHAR, BUFFER_SMALL> utf16Str1;
257 Firebird::HalfStaticArray<UCHAR, BUFFER_SMALL> utf16Str2;
258 UCHAR utf16Space[sizeof(ULONG)];
259
260 if (getCharSet()->isMultiByte())
261 {
262 // convert str1 to UTF-16
263 ULONG utf16Length = getCharSet()->getConvToUnicode().convertLength(len1);
264
265 len1 = getCharSet()->getConvToUnicode().convert(len1, str1,
266 utf16Length, utf16Str1.getBuffer(utf16Length));
267 str1 = utf16Str1.begin();
268
269 // convert str2 to UTF-16
270 utf16Length = getCharSet()->getConvToUnicode().convertLength(len2);
271
272 len2 = getCharSet()->getConvToUnicode().convert(len2, str2,
273 utf16Length, utf16Str2.getBuffer(utf16Length));
274 str2 = utf16Str2.begin();
275
276 // convert charset space to UTF-16
277 spaceLength =
278 getCharSet()->getConvToUnicode().convert(spaceLength, space, sizeof(utf16Space), utf16Space);
279 fb_assert(spaceLength == 2); // space character can't be surrogate for default compare
280 space = utf16Space;
281 }
282
283 if (tt->texttype_pad_option)
284 {
285 const UCHAR* pad;
286
287 for (pad = str1 + len1 - spaceLength; pad >= str1; pad -= spaceLength)
288 {
289 if (memcmp(pad, space, spaceLength) != 0)
290 break;
291 }
292
293 len1 = pad - str1 + spaceLength;
294
295 for (pad = str2 + len2 - spaceLength; pad >= str2; pad -= spaceLength)
296 {
297 if (memcmp(pad, space, spaceLength) != 0)
298 break;
299 }
300
301 len2 = pad - str2 + spaceLength;
302 }
303
304 if (getCharSet()->isMultiByte())

Callers

nothing calls this directly

Calls 8

getSpaceLengthMethod · 0.80
isMultiByteMethod · 0.80
getConvToUnicodeMethod · 0.80
getSpaceMethod · 0.45
convertLengthMethod · 0.45
convertMethod · 0.45
getBufferMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected