MCPcopy Create free account
hub / github.com/devsisters/libquic / DoIsStringASCII

Function DoIsStringASCII

src/base/strings/string_util.cc:472–499  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

470
471template <class Char>
472inline bool DoIsStringASCII(const Char* characters, size_t length) {
473 MachineWord all_char_bits = 0;
474 const Char* end = characters + length;
475
476 // Prologue: align the input.
477 while (!IsAlignedToMachineWord(characters) && characters != end) {
478 all_char_bits |= *characters;
479 ++characters;
480 }
481
482 // Compare the values of CPU word size.
483 const Char* word_end = AlignToMachineWord(end);
484 const size_t loop_increment = sizeof(MachineWord) / sizeof(Char);
485 while (characters < word_end) {
486 all_char_bits |= *(reinterpret_cast<const MachineWord*>(characters));
487 characters += loop_increment;
488 }
489
490 // Process the remaining bytes.
491 while (characters != end) {
492 all_char_bits |= *characters;
493 ++characters;
494 }
495
496 MachineWord non_ascii_bit_mask =
497 NonASCIIMask<sizeof(MachineWord), Char>::value();
498 return !(all_char_bits & non_ascii_bit_mask);
499}
500
501bool IsStringASCII(const StringPiece& str) {
502 return DoIsStringASCII(str.data(), str.length());

Callers 1

IsStringASCIIFunction · 0.85

Calls 3

IsAlignedToMachineWordFunction · 0.85
AlignToMachineWordFunction · 0.85
valueFunction · 0.50

Tested by

no test coverage detected