Changeset 192 for trunk/src/helpers/encodings.c
- Timestamp:
- Jul 25, 2002, 11:51:53 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/encodings.c
r191 r192 3 3 *@@sourcefile encodings.c: 4 4 * character encoding support. Handles all kinds 5 * of legacy codepages (including most OS/2 codepage )5 * of legacy codepages (including most OS/2 codepages) 6 6 * and Unicode in the form of UTF-8 and translations 7 7 * between then. … … 10 10 * 11 11 * Be warned, compilation of this file takes a long 12 * file because this includes all the complex codepage 12 * file because this includes all the complex codepages 13 13 * from include\encodings. 14 14 * … … 163 163 *ppMap = G_aEncodings[ul].pMap; 164 164 *pcEntries = G_aEncodings[ul].cEntries; 165 return (1);165 return 1; 166 166 } 167 167 } 168 168 169 return (0);169 return 0; 170 170 } 171 171 … … 198 198 } 199 199 200 return (UNSUPPORTED);200 return UNSUPPORTED; 201 201 } 202 202 … … 330 330 } 331 331 332 return (pTableNew);332 return pTableNew; 333 333 } 334 334 … … 385 385 && (c <= pTable->usHighestCP) 386 386 ) 387 return (pTable->ausEntriesUniFromCP[c]);388 389 return (0xFFFF);387 return pTable->ausEntriesUniFromCP[c]; 388 389 return 0xFFFF; 390 390 } 391 391 … … 410 410 && (ulUni <= pTable->usHighestUni) 411 411 ) 412 return (pTable->ausEntriesCPFromUni[ulUni]);413 414 return (0xFFFF);412 return pTable->ausEntriesCPFromUni[ulUni]; 413 414 return 0xFFFF; 415 415 } 416 416 … … 445 445 { 446 446 unsigned long ulChar; 447 unsigned long ulCount; 448 int fIllegal; 447 449 448 450 if (!(ulChar = **ppch)) … … 455 457 { 456 458 (*ppch)++; 457 return (ulChar); 459 return ulChar; 460 } 461 462 ulCount = 1; 463 fIllegal = 0; 464 465 // note: 0xc0 and 0xc1 are reserved and 466 // cannot appear as the first UTF-8 byte 467 468 if ( (ulChar >= 0xc2) 469 && (ulChar < 0xe0) 470 ) 471 { 472 // that's two bytes 473 ulCount = 2; 474 ulChar &= 0x1f; 475 } 476 else if ((ulChar & 0xf0) == 0xe0) 477 { 478 // three bytes 479 ulCount = 3; 480 ulChar &= 0x0f; 481 } 482 else if ((ulChar & 0xf8) == 0xf0) 483 { 484 // four bytes 485 ulCount = 4; 486 ulChar &= 0x07; 487 } 488 else if ((ulChar & 0xfc) == 0xf8) 489 { 490 // five bytes 491 ulCount = 5; 492 ulChar &= 0x03; 493 } 494 else if ((ulChar & 0xfe) == 0xfc) 495 { 496 // six bytes 497 ulCount = 6; 498 ulChar &= 0x01; 458 499 } 459 500 else 460 {461 unsigned long ulCount = 1; 462 int fIllegal = 0;463 464 // note: 0xc0 and 0xc1 are reserved and465 // cannot appear as the first UTF-8 byte466 467 if ( (ulChar >= 0xc2)468 && (ulChar < 0xe0)469 )501 ++fIllegal; 502 503 if (!fIllegal) 504 { 505 // go for the second and more bytes then 506 int ul2; 507 508 for (ul2 = 1; 509 ul2 < ulCount; 510 ++ul2) 470 511 { 471 // that's two bytes 472 ulCount = 2; 473 ulChar &= 0x1f; 512 unsigned long ulChar2 = *((*ppch) + ul2); 513 514 if (!(ulChar2 & 0xc0)) // != 0x80) 515 { 516 ++fIllegal; 517 break; 518 } 519 520 ulChar <<= 6; 521 ulChar |= ulChar2 & 0x3f; 474 522 } 475 else if ((ulChar & 0xf0) == 0xe0) 523 } 524 525 if (fIllegal) 526 { 527 // skip all the following characters 528 // until we find something with bit 7 off 529 do 476 530 { 477 // three bytes 478 ulCount = 3; 479 ulChar &= 0x0f; 480 } 481 else if ((ulChar & 0xf8) == 0xf0) 482 { 483 // four bytes 484 ulCount = 4; 485 ulChar &= 0x07; 486 } 487 else if ((ulChar & 0xfc) == 0xf8) 488 { 489 // five bytes 490 ulCount = 5; 491 ulChar &= 0x03; 492 } 493 else if ((ulChar & 0xfe) == 0xfc) 494 { 495 // six bytes 496 ulCount = 6; 497 ulChar &= 0x01; 498 } 499 else 500 ++fIllegal; 501 502 if (!fIllegal) 503 { 504 // go for the second and more bytes then 505 int ul2; 506 507 for (ul2 = 1; 508 ul2 < ulCount; 509 ++ul2) 510 { 511 unsigned long ulChar2 = *((*ppch) + ul2); 512 513 if (!(ulChar2 & 0xc0)) // != 0x80) 514 { 515 ++fIllegal; 516 break; 517 } 518 519 ulChar <<= 6; 520 ulChar |= ulChar2 & 0x3f; 521 } 522 } 523 524 if (fIllegal) 525 { 526 // skip all the following characters 527 // until we find something with bit 7 off 528 do 529 { 530 ulChar = *(++(*ppch)); 531 if (!ulChar) 532 break; 533 } while (ulChar & 0x80); 534 } 535 else 536 *ppch += ulCount; 537 } 538 539 return (ulChar); 531 ulChar = *(++(*ppch)); 532 if (!ulChar) 533 break; 534 } while (ulChar & 0x80); 535 } 536 else 537 *ppch += ulCount; 538 539 return ulChar; 540 540 } 541 541
Note:
See TracChangeset
for help on using the changeset viewer.