File: util.hh

package info (click to toggle)
ruby-unf-ext 0.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,128 kB
  • ctags: 147
  • sloc: cpp: 14,043; ruby: 79; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 619 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef UNF_UTIL_HH
#define UNF_UTIL_HH

namespace UNF {
  namespace Util {
    inline bool is_utf8_char_start_byte(char byte) {
      if(!(byte&0x80))    return true; // ascii
      else if (byte&0x40) return true; // start of a UTF-8 character byte sequence
      return false;
    }

    inline const char* nearest_utf8_char_start_point(const char* s) {
      for(; is_utf8_char_start_byte(*s)==false; s++);
      return s;
    }

    template <class CharStream>
    inline void eat_until_utf8_char_start_point(CharStream& in) {
      for(; is_utf8_char_start_byte(in.peek())==false; in.read());
    }
  }
}

#endif