MCPcopy Create free account
hub / github.com/cppla/ServerStatus / str_utf8_decode

Function str_utf8_decode

server/src/system.c:1921–1969  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1919}
1920
1921int str_utf8_decode(const char **ptr)
1922{
1923 const char *buf = *ptr;
1924 int ch = 0;
1925
1926 do
1927 {
1928 if((*buf&0x80) == 0x0) /* 0xxxxxxx */
1929 {
1930 ch = *buf;
1931 buf++;
1932 }
1933 else if((*buf&0xE0) == 0xC0) /* 110xxxxx */
1934 {
1935 ch = (*buf++ & 0x3F) << 6; if(!(*buf)) break;
1936 ch += (*buf++ & 0x3F);
1937 if(ch == 0) ch = -1;
1938 }
1939 else if((*buf & 0xF0) == 0xE0) /* 1110xxxx */
1940 {
1941 ch = (*buf++ & 0x1F) << 12; if(!(*buf)) break;
1942 ch += (*buf++ & 0x3F) << 6; if(!(*buf)) break;
1943 ch += (*buf++ & 0x3F);
1944 if(ch == 0) ch = -1;
1945 }
1946 else if((*buf & 0xF8) == 0xF0) /* 11110xxx */
1947 {
1948 ch = (*buf++ & 0x0F) << 18; if(!(*buf)) break;
1949 ch += (*buf++ & 0x3F) << 12; if(!(*buf)) break;
1950 ch += (*buf++ & 0x3F) << 6; if(!(*buf)) break;
1951 ch += (*buf++ & 0x3F);
1952 if(ch == 0) ch = -1;
1953 }
1954 else
1955 {
1956 /* invalid */
1957 buf++;
1958 break;
1959 }
1960
1961 *ptr = buf;
1962 return ch;
1963 } while(0);
1964
1965 /* out of bounds */
1966 *ptr = buf;
1967 return -1;
1968
1969}
1970
1971int str_utf8_check(const char *str)
1972{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected