Changeset 64814 in vbox
- Timestamp:
- Dec 8, 2016 9:37:21 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/bldprog-strtab-template.cpp.h
r62450 r64814 116 116 117 117 118 119 118 /** String table data. */ 120 119 typedef struct BLDPROGSTRTAB … … 227 226 #endif 228 227 229 230 #ifdef BLDPROG_STRTAB_WITH_COMPRESSION 228 #ifdef BLDPROG_STRTAB_WITH_COMPRESSION 229 231 230 DECLINLINE(size_t) bldProgStrTab_compressorFindNextWord(const char *pszSrc, char ch, const char **ppszSrc) 232 231 { … … 275 274 } 276 275 276 277 277 /** 278 278 * Analyzes a string. … … 342 342 } 343 343 } 344 344 345 #endif /* BLDPROG_STRTAB_WITH_COMPRESSION */ 345 346 346 347 347 /** … … 392 392 pThis->cchUniqueStrings += pStr->cchString; 393 393 } 394 395 394 396 395 … … 414 413 } 415 414 416 417 418 #ifdef BLDPROG_STRTAB_WITH_COMPRESSION 415 #ifdef BLDPROG_STRTAB_WITH_COMPRESSION 416 417 /** 418 * Copies @a cchSrc chars from @a pchSrc to @a pszDst, escaping special 419 * sequences. 420 * 421 * @returns New @a pszDst position, NULL if invalid source encoding. 422 * @param pszDst The destination buffer. 423 * @param pszSrc The source buffer. 424 * @param cchSrc How much to copy. 425 */ 426 static char *bldProgStrTab_compressorCopyAndEscape(char *pszDst, const char *pszSrc, size_t cchSrc) 427 { 428 while (cchSrc-- > 0) 429 { 430 char ch = *pszSrc; 431 if (!((unsigned char)ch & 0x80)) 432 { 433 *pszDst++ = ch; 434 pszSrc++; 435 } 436 else 437 { 438 # ifdef BLDPROG_STRTAB_PURE_ASCII 439 fprintf(stderr, "error: unexpected char value %#x\n", ch); 440 return NULL; 441 # else 442 RTUNICP uc; 443 int rc = RTStrGetCpEx(&pszSrc, &uc); 444 if (RT_SUCCESS(rc)) 445 { 446 *pszDst++ = (unsigned char)0xff; /* escape single code point. */ 447 pszDst = RTStrPutCp(pszDst, uc); 448 } 449 else 450 { 451 fprintf(stderr, "Error: RTStrGetCpEx failed with rc=%d\n", rc); 452 return NULL; 453 } 454 # endif 455 } 456 } 457 return pszDst; 458 } 459 419 460 420 461 /** … … 434 475 while ((ch = *pszSrc) != '\0') 435 476 { 477 const char * const pszSrcUncompressed = pszSrc; 436 478 size_t cchWord = bldProgStrTab_compressorFindNextWord(pszSrc, ch, &pszSrc); 479 size_t cchSrcUncompressed = pszSrc - pszSrcUncompressed; 480 if (cchSrcUncompressed > 0) 481 { 482 pszDst = bldProgStrTab_compressorCopyAndEscape(pszDst, pszSrcUncompressed, cchSrcUncompressed); 483 if (!pszDst) 484 return false; 485 } 437 486 if (!cchWord) 438 487 break; … … 457 506 { 458 507 /* Copy the current word. */ 459 ch = *pszSrc; 460 do 461 { 462 if (!((unsigned char)ch & 0x80)) 463 { 464 *pszDst++ = ch; 465 pszSrc++; 466 } 467 else 468 { 469 #ifdef BLDPROG_STRTAB_PURE_ASCII 470 fprintf(stderr, "error: unexpected char value %#x\n", ch); 471 return false; 472 #else 473 RTUNICP uc; 474 int rc = RTStrGetCpEx(&pszSrc, &uc); 475 if (RT_SUCCESS(rc)) 476 { 477 *pszDst++ = (unsigned char)0xff; /* escape single code point. */ 478 pszDst = RTStrPutCp(pszDst, uc); 479 } 480 else 481 { 482 fprintf(stderr, "Error: RTStrGetCpEx failed with rc=%d\n", rc); 483 return false; 484 } 485 #endif 486 } 487 } while ((ch = *pszSrc) != '\0' && ch != ' '); 508 pszDst = bldProgStrTab_compressorCopyAndEscape(pszDst, pszSrc, cchWord); 509 if (!pszDst) 510 return false; 511 pszSrc += cchWord; 488 512 } 489 513 } … … 630 654 631 655 #endif /* BLDPROG_STRTAB_WITH_COMPRESSION */ 632 633 656 634 657 /**
Note:
See TracChangeset
for help on using the changeset viewer.