* this function tests if the string pointed by inptr represents * an HTML entity, in decimal form ( e.g. Å), in hexadecimal * form ( e.g. 水 ), or from html 4.0 spec ( e.g. é ) * - returns returns 0 if the string doesn't represent such an entity. * - if the string does start with such entity,it returns the number of * bytes occupied by said entity, and stores the unicode
| 1966 | * bytes occupied by said entity, and stores the unicode value in *unicode |
| 1967 | */ |
| 1968 | int msGetUnicodeEntity(const char *inptr, int *unicode) { |
| 1969 | unsigned char *in = (unsigned char*)inptr; |
| 1970 | int l,val=0; |
| 1971 | if(*in=='&') { |
| 1972 | in++; |
| 1973 | if(*in=='#') { |
| 1974 | in++; |
| 1975 | if(*in=='x'||*in=='X') { |
| 1976 | in++; |
| 1977 | for(l=3;l<8;l++) { |
| 1978 | char byte; |
| 1979 | if(*in>='0'&&*in<='9') |
| 1980 | byte = *in - '0'; |
| 1981 | else if(*in>='a'&&*in<='f') |
| 1982 | byte = *in - 'a' + 10; |
| 1983 | else if(*in>='A'&&*in<='F') |
| 1984 | byte = *in - 'A' + 10; |
| 1985 | else |
| 1986 | break; |
| 1987 | in++; |
| 1988 | val = (val * 16) + byte; |
| 1989 | } |
| 1990 | if(*in==';' && l>3 ) { |
| 1991 | *unicode=val; |
| 1992 | return ++l; |
| 1993 | } |
| 1994 | } |
| 1995 | else |
| 1996 | { |
| 1997 | for(l=2;l<8;l++) { |
| 1998 | if(*in>='0'&&*in<='9') { |
| 1999 | val = val*10+*in-'0'; |
| 2000 | in++; |
| 2001 | } |
| 2002 | else |
| 2003 | break; |
| 2004 | } |
| 2005 | if(*in==';' && l>2 ) { |
| 2006 | *unicode=val; |
| 2007 | return ++l; |
| 2008 | } |
| 2009 | } |
| 2010 | } |
| 2011 | else |
| 2012 | { |
| 2013 | char entity_name_buf[MAP_ENTITY_NAME_LENGTH_MAX+1]; |
| 2014 | char *p; |
| 2015 | struct mapentities_s key, *res; |
| 2016 | key.name = p = entity_name_buf; |
| 2017 | for (l = 1; l <= MAP_ENTITY_NAME_LENGTH_MAX+1; l++) |
| 2018 | { |
| 2019 | if (*in == '\0') /*end of string before possible entity: return*/ |
| 2020 | break; |
| 2021 | if (*in == ';') /*possible end of entity: do a lookup*/ |
| 2022 | { |
| 2023 | *p++ = '\0'; |
| 2024 | res = bsearch(&key, mapentities, MAP_NR_OF_ENTITIES, |
| 2025 | sizeof(mapentities[0]), *cmp_entities); |
no outgoing calls
no test coverage detected