From: porkchop@invalid.foo   
      
   On Sat, 15 Nov 2025 06:24:39 +0100, Bonita Montero wrote:   
      
   > A little bugfix and a perfect style:   
   >   
   > #include    
   > #include    
   > #include    
   > #include    
   >   
   > using namespace std;   
   >   
   > optional utf8Width( u8string_view str )   
   > {   
   > size_t w = 0;   
   > for( auto it = str.begin(); it != str.end(); ++w ) [[likely]]   
   > if( size_t head = countl_zero( (unsigned char)~*it ); head <= 4   
   > && (size_t)(str.end() - it) >= head + 1 ) [[likely]]   
   > it += head + 1;   
   > else   
   > return nullopt;   
   > return w;   
   > }   
   >   
   > int main()   
   > {   
   > cout << *utf8Width( u8"Hello, 世界!" ) << endl;   
   > }   
      
   Very excited. =) It is very useful for someone to use   
   native characters...   
      
   ./tinybase -s='世界' data/books.tbf   
      
   FILE: data/books.tbf   
   LINE: 1   
   BLOCK: 1   
   CRC-8: 0xf2   
   QUERY: 世界   
   MATCH: 世界   
      
   TAGS: book, 1984, George Orwell, 1949, Dystopian Fiction, <世界>   
      
   --   
   :wq   
   Mike Sanders   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|