Doxygen
utf8.cpp 文件参考
#include <cstdint>
#include <sstream>
#include "utf8.h"
#include "caseconvert.h"
#include "textstream.h"
+ utf8.cpp 的引用(Include)关系图:

浏览源代码.

函数

uint8_t getUTF8CharNumBytes (char c)
 Returns the number of bytes making up a single UTF8 character given the first byte in the sequence. 更多...
 
static uint32_t decode_utf8 (const char *data, int numBytes) noexcept
 Decodes a given input of utf8 data to a unicode code point given the number of bytes it's made of 更多...
 
static uint32_t convertUTF8CharToUnicode (const char *s, size_t bytesLeft, int &len)
 
std::string getUTF8CharAt (const std::string &input, size_t pos)
 Returns the UTF8 character found at byte position pos in the input string. 更多...
 
uint32_t getUnicodeForUTF8CharAt (const std::string &input, size_t pos)
 Returns the 32bit Unicode value matching character at byte position pos in the UTF8 encoded input. 更多...
 
static char asciiToLower (uint32_t code)
 
static char asciiToUpper (uint32_t code)
 
static std::string caseConvert (const std::string &input, char(*asciiConversionFunc)(uint32_t code), const char *(*conversionFunc)(uint32_t code))
 
std::string convertUTF8ToLower (const std::string &input)
 Converts the input string into a lower case version, also taking into account non-ASCII characters that has a lower case variant. 更多...
 
std::string convertUTF8ToUpper (const std::string &input)
 Converts the input string into a upper case version, also taking into account non-ASCII characters that has a upper case variant. 更多...
 
const char * writeUTF8Char (TextStream &t, const char *s)
 Writes the UTF8 character pointed to by s to stream t and returns a pointer to the next character. 更多...
 
bool lastUTF8CharIsMultibyte (const std::string &input)
 Returns true iff the last character in input is a multibyte character. 更多...
 
bool isUTF8CharUpperCase (const std::string &input, size_t pos)
 Returns true iff the input string at byte position pos holds an upper case character. 更多...
 
int isUTF8NonBreakableSpace (const char *input)
 Check if the first character pointed at by input is a non-breakable whitespace character. 更多...
 

函数说明

◆ asciiToLower()

static char asciiToLower ( uint32_t  code)
inlinestatic

在文件 utf8.cpp142 行定义.

143 {
144  return code>='A' && code<='Z' ? (char)(code+'a'-'A') : (char)code;
145 }

被这些函数引用 convertUTF8ToLower().

◆ asciiToUpper()

static char asciiToUpper ( uint32_t  code)
inlinestatic

在文件 utf8.cpp147 行定义.

148 {
149  return code>='a' && code<='z' ? (char)(code+'A'-'a') : (char)code;
150 }

被这些函数引用 convertUTF8ToUpper().

◆ caseConvert()

static std::string caseConvert ( const std::string &  input,
char(*)(uint32_t code)  asciiConversionFunc,
const char *(*)(uint32_t code)  conversionFunc 
)
inlinestatic

在文件 utf8.cpp152 行定义.

155 {
156  uint32_t code;
157  std::string result;
158  result.reserve(input.length()); // assume all ASCII characters
159  int len;
160  size_t bytesLeft = input.length();
161  const char *p = input.c_str();
162  while ((code=convertUTF8CharToUnicode(p,bytesLeft,len)))
163  {
164  if (code<128) // ASCII case
165  {
166  char c = asciiConversionFunc(code);
167  result+=c;
168  }
169  else // generic case
170  {
171  const char *conv = conversionFunc(code);
172  if (conv==nullptr) // no difference between lower and upper case
173  {
174  result.append(p,len);
175  }
176  else // replace the input character with the conversion result
177  {
178  result.append(conv);
179  }
180  }
181  p+=len;
182  bytesLeft-=len;
183  }
184  return result;
185 }

引用了 convertUTF8CharToUnicode().

被这些函数引用 convertUTF8ToLower() , 以及 convertUTF8ToUpper().

◆ convertUTF8CharToUnicode()

static uint32_t convertUTF8CharToUnicode ( const char *  s,
size_t  bytesLeft,
int &  len 
)
inlinestatic

在文件 utf8.cpp69 行定义.

70 {
71  if (s==0 || bytesLeft==0)
72  {
73  len=0;
74  return 0;
75  }
76  unsigned char uc = static_cast<unsigned char>(*s);
77  if (uc<128) // ASCII case
78  {
79  len=1;
80  return uc;
81  }
82  switch (bytesLeft)
83  {
84  default:
85  if ((uc&0xFEu)==0xFCu)// 1111110X six bytes
86  {
87  len=6;
88  return decode_utf8(s,len);
89  }
90  // fall through
91  case 5:
92  if ((uc&0xFCu)==0xF8u) // 111110XX five bytes
93  {
94  len=5;
95  return decode_utf8(s,len);
96  }
97  // fall through
98  case 4:
99  if ((uc&0xF8u)==0xF0u) // 11110XXX four bytes
100  {
101  len=4;
102  return decode_utf8(s,len);
103  }
104  // fall through
105  case 3:
106  if ((uc&0xF0u)==0xE0u) // 1110XXXX three bytes
107  {
108  len=3;
109  return decode_utf8(s,len);
110  }
111  // fall through
112  case 2:
113  if ((uc&0xE0u)==0xC0u) // 110XXXXX two bytes
114  {
115  len=2;
116  return decode_utf8(s,len);
117  }
118  // fall through
119  case 1:
120  {
121  len=1;
122  return uc;
123  }
124  }
125 }

引用了 decode_utf8().

被这些函数引用 caseConvert(), getUnicodeForUTF8CharAt() , 以及 isUTF8CharUpperCase().

◆ convertUTF8ToLower()

std::string convertUTF8ToLower ( const std::string &  input)

Converts the input string into a lower case version, also taking into account non-ASCII characters that has a lower case variant.

在文件 utf8.cpp187 行定义.

188 {
190 }

引用了 asciiToLower(), caseConvert() , 以及 convertUnicodeToLower().

被这些函数引用 addClassMemberNameToIndex(), addFileMemberNameToIndex(), addMemberToSearchIndex(), addNamespaceMemberNameToIndex(), createJavaScriptSearchIndex(), QCString::lower() , 以及 searchId().

◆ convertUTF8ToUpper()

std::string convertUTF8ToUpper ( const std::string &  input)

Converts the input string into a upper case version, also taking into account non-ASCII characters that has a upper case variant.

在文件 utf8.cpp192 行定义.

193 {
195 }

引用了 asciiToUpper(), caseConvert() , 以及 convertUnicodeToUpper().

被这些函数引用 FilterAlphaIndex::determineSortKey(), QCString::upper() , 以及 writeAlphabeticalClassList().

◆ decode_utf8()

static uint32_t decode_utf8 ( const char *  data,
int  numBytes 
)
inlinestaticnoexcept

Decodes a given input of utf8 data to a unicode code point given the number of bytes it's made of

在文件 utf8.cpp55 行定义.

56 {
57  uint32_t cp = (unsigned char)*data;
58  if (numBytes>1)
59  {
60  cp &= 0x7F >> numBytes; // Mask out the header bits
61  for (int i=1 ; i<numBytes ; i++)
62  {
63  cp = (cp<<6) | ((unsigned char)data[i]&0x3F);
64  }
65  }
66  return cp;
67 }

被这些函数引用 convertUTF8CharToUnicode().

◆ getUnicodeForUTF8CharAt()

uint32_t getUnicodeForUTF8CharAt ( const std::string &  input,
size_t  pos 
)

Returns the 32bit Unicode value matching character at byte position pos in the UTF8 encoded input.

在文件 utf8.cpp135 行定义.

136 {
137  std::string charS = getUTF8CharAt(input,pos);
138  int len;
139  return convertUTF8CharToUnicode(charS.c_str(),charS.length(),len);
140 }

引用了 convertUTF8CharToUnicode() , 以及 getUTF8CharAt().

◆ getUTF8CharAt()

std::string getUTF8CharAt ( const std::string &  input,
size_t  pos 
)

Returns the UTF8 character found at byte position pos in the input string.

The resulting string can be a multi byte sequence.

在文件 utf8.cpp127 行定义.

128 {
129  if (input.length()<=pos) return std::string();
130  int numBytes=getUTF8CharNumBytes(input[pos]);
131  if (input.length()<pos+numBytes) return std::string();
132  return input.substr(pos,pos+numBytes);
133 }

引用了 getUTF8CharNumBytes().

被这些函数引用 addClassMemberNameToIndex(), addFileMemberNameToIndex(), addMemberToSearchIndex(), addNamespaceMemberNameToIndex(), createJavaScriptSearchIndex(), FilterAlphaIndex::determineSortKey(), getUnicodeForUTF8CharAt() , 以及 writeAlphabeticalClassList().

◆ getUTF8CharNumBytes()

uint8_t getUTF8CharNumBytes ( char  c)

Returns the number of bytes making up a single UTF8 character given the first byte in the sequence.

在文件 utf8.cpp23 行定义.

24 {
25  uint8_t num=1;
26  unsigned char uc = static_cast<unsigned char>(c);
27  if (uc>=0x80u) // multibyte character
28  {
29  if ((uc&0xE0u)==0xC0u)
30  {
31  num=2; // 110x.xxxx: 2 byte character
32  }
33  if ((uc&0xF0u)==0xE0u)
34  {
35  num=3; // 1110.xxxx: 3 byte character
36  }
37  if ((uc&0xF8u)==0xF0u)
38  {
39  num=4; // 1111.0xxx: 4 byte character
40  }
41  if ((uc&0xFCu)==0xF8u)
42  {
43  num=5; // 1111.10xx: 5 byte character
44  }
45  if ((uc&0xFEu)==0xFCu)
46  {
47  num=6; // 1111.110x: 6 byte character
48  }
49  }
50  return num;
51 }

被这些函数引用 Markdown::detab(), escapeCharsInString(), getUTF8CharAt(), nextUTF8CharPosition() , 以及 writeUTF8Char().

◆ isUTF8CharUpperCase()

bool isUTF8CharUpperCase ( const std::string &  input,
size_t  pos 
)

Returns true iff the input string at byte position pos holds an upper case character.

在文件 utf8.cpp218 行定义.

219 {
220  if (input.length()<=pos) return false;
221  int len;
222  // turn the UTF8 character at position pos into a unicode value
223  uint32_t code = convertUTF8CharToUnicode(input.c_str()+pos,input.length()-pos,len);
224  // check if the character can be converted to lower case, if so it was an upper case character
225  return convertUnicodeToLower(code)!=nullptr;
226 }

引用了 convertUnicodeToLower() , 以及 convertUTF8CharToUnicode().

被这些函数引用 DefinitionImpl::_setBriefDescription().

◆ isUTF8NonBreakableSpace()

int isUTF8NonBreakableSpace ( const char *  input)

Check if the first character pointed at by input is a non-breakable whitespace character.

Returns the byte size of the character if there is match or 0 if not.

在文件 utf8.cpp228 行定义.

229 {
230  return (static_cast<unsigned char>(input[0])==0xC2 &&
231  static_cast<unsigned char>(input[1])==0xA0) ? 2 : 0;
232 }

被这些函数引用 Markdown::detab().

◆ lastUTF8CharIsMultibyte()

bool lastUTF8CharIsMultibyte ( const std::string &  input)

Returns true iff the last character in input is a multibyte character.

在文件 utf8.cpp212 行定义.

213 {
214  // last byte is part of a multibyte UTF8 char if bit 8 is set and bit 7 is not
215  return !input.empty() && (((unsigned char)input[input.length()-1])&0xC0)==0x80;
216 }

被这些函数引用 DefinitionImpl::_setBriefDescription().

◆ writeUTF8Char()

const char* writeUTF8Char ( TextStream t,
const char *  s 
)

Writes the UTF8 character pointed to by s to stream t and returns a pointer to the next character.

在文件 utf8.cpp197 行定义.

198 {
199  if (s==0) return 0;
200  uint8_t len = getUTF8CharNumBytes(*s);
201  for (uint8_t i=0;i<len;i++)
202  {
203  if (s[i]==0) // detect premature end of string (due to invalid UTF8 char)
204  {
205  len=i;
206  }
207  }
208  t.write(s,len);
209  return s+len;
210 }

引用了 getUTF8CharNumBytes() , 以及 TextStream::write().

被这些函数引用 HtmlCodeGenerator::codify(), ManGenerator::codify(), RTFGenerator::codify() , 以及 writeXMLCodeString().

convertUnicodeToUpper
const char * convertUnicodeToUpper(uint32_t code)
Definition: caseconvert.h:12
asciiToUpper
static char asciiToUpper(uint32_t code)
Definition: utf8.cpp:147
caseConvert
static std::string caseConvert(const std::string &input, char(*asciiConversionFunc)(uint32_t code), const char *(*conversionFunc)(uint32_t code))
Definition: utf8.cpp:152
decode_utf8
static uint32_t decode_utf8(const char *data, int numBytes) noexcept
Decodes a given input of utf8 data to a unicode code point given the number of bytes it's made of
Definition: utf8.cpp:55
getUTF8CharAt
std::string getUTF8CharAt(const std::string &input, size_t pos)
Returns the UTF8 character found at byte position pos in the input string.
Definition: utf8.cpp:127
convertUTF8CharToUnicode
static uint32_t convertUTF8CharToUnicode(const char *s, size_t bytesLeft, int &len)
Definition: utf8.cpp:69
getUTF8CharNumBytes
uint8_t getUTF8CharNumBytes(char c)
Returns the number of bytes making up a single UTF8 character given the first byte in the sequence.
Definition: utf8.cpp:23
convertUnicodeToLower
const char * convertUnicodeToLower(uint32_t code)
Definition: caseconvert.h:1505
asciiToLower
static char asciiToLower(uint32_t code)
Definition: utf8.cpp:142
TextStream::write
void write(const char *buf, size_t len)
Adds a array of character to the stream
Definition: textstream.h:180