Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdbool.h>
- /* Basic signs over 127 and lower than 256*/
- const char *umap[][2] =
- {
- {"#x80","€"},
- {"#x81"," "},
- {"#x82","‚"},
- {"#x83","ƒ"},
- {"#x84","„"},
- {"#x85","…"},
- {"#x86","†"},
- {"#x87","‡"},
- {"#x88","ˆ"},
- {"#x89","‰"},
- {"#x8A","Š"},
- {"#x8B","‹"},
- {"#x8C","Œ"},
- {"#x8D"," "},
- {"#x8E","Ž"},
- {"#x8F"," "},
- {"#x90"," "},
- {"#x91","‘"},
- {"#x92","’"},
- {"#x93","“"},
- {"#x94","”"},
- {"#x95","•"},
- {"#x96","–"},
- {"#x97","—"},
- {"#x98","˜"},
- {"#x99","™"},
- {"#x9A","š"},
- {"#x9B","›"},
- {"#x9C","œ"},
- {"#x9D"," "},
- {"#x9E","ž"},
- {"#x9F","Ÿ"},
- {"nbsp",""},
- {"iexcl","¡"},
- {"cent","¢"},
- {"pound","£"},
- {"curren","¤"},
- {"yen","¥"},
- {"brvbar","¦"},
- {"sect","§"},
- {"uml","¨"},
- {"copy","©"},
- {"ordf","ª"},
- {"laquo","«"},
- {"not","¬"},
- {"shy",""},
- {"reg","®"},
- {"macr","¯"},
- {"deg","°"},
- {"plusmn","±"},
- {"sup2","²"},
- {"sup3","³"},
- {"acute","´"},
- {"micro","µ"},
- {"para","¶"},
- {"middot","·"},
- {"cedil","¸"},
- {"sup1","¹"},
- {"ordm","º"},
- {"raquo","»"},
- {"frac14","¼"},
- {"frac12","½"},
- {"frac34","¾"},
- {"iquest","¿"},
- {"Agrave","À"},
- {"Aacute","Á"},
- {"Acirc","Â"},
- {"Atilde","Ã"},
- {"Auml","Ä"},
- {"Aring","Å"},
- {"AElig","Æ"},
- {"Ccedil","Ç"},
- {"Egrave","È"},
- {"Eacute","É"},
- {"Ecirc","Ê"},
- {"Euml","Ë"},
- {"Igrave","Ì"},
- {"Iacute","Í"},
- {"Icirc","Î"},
- {"Iuml","Ï"},
- {"ETH","Ð"},
- {"Ntilde","Ñ"},
- {"Ograve","Ò"},
- {"Oacute","Ó"},
- {"Ocirc","Ô"},
- {"Otilde","Õ"},
- {"Ouml","Ö"},
- {"times","×"},
- {"Oslash","Ø"},
- {"Ugrave","Ù"},
- {"Uacute","Ú"},
- {"Ucirc","Û"},
- {"Uuml","Ü"},
- {"Yacute","Ý"},
- {"THORN","Þ"},
- {"szlig","ß"},
- {"agrave","à"},
- {"aacute","á"},
- {"acirc","â"},
- {"atilde","ã"},
- {"auml","ä"},
- {"aring","å"},
- {"aelig","æ"},
- {"ccedil","ç"},
- {"egrave","è"},
- {"eacute","é"},
- {"ecirc","ê"},
- {"euml","ë"},
- {"igrave","ì"},
- {"iacute","í"},
- {"icirc","î"},
- {"iuml","ï"},
- {"eth","ð"},
- {"ntilde","ñ"},
- {"ograve","ò"},
- {"oacute","ó"},
- {"ocirc","ô"},
- {"otilde","õ"},
- {"ouml","ö"},
- {"divide","÷"},
- {"oslash","ø"},
- {"ugrave","ù"},
- {"uacute","ú"},
- {"ucirc","û"},
- {"uuml","ü"},
- {"yacute","ý"},
- {"thorn","þ"},
- {"yuml","ÿ"},
- {"#x2500","─"},
- {"#x2502","│"},
- {"#x250C","┌"},
- {"#x2510","┐"},
- {"#x2514","└"},
- {"#x2518","┘"},
- {"#x251C","├"},
- {"#x2524","┤"},
- {"#x252C","┬"},
- {"#x2534","┴"},
- {"#x253C","┼"},
- {"#x3B1","α"},
- {"#x3B2","β"},
- {"#x3B3","γ"},
- {"#x394","Δ"},
- {"#x2211","∑"},
- {"#x221A","√"},
- {"#x222B","∫"},
- {"#x2248","≈"},
- {"#x2260","≠"},
- {"#x2264","≤"},
- {"#x2265","≥"},
- {"#x2190","←"},
- {"#x2191","↑"},
- {"#x2192","→"},
- {"#x2193","↓"},
- {"#x2194","↔"},
- {"#x2195","↕"},
- {"#x2022","•"},
- {"#x2044","⁄"},
- {"#x2030","‰"},
- {"#x2122","™"},
- {"#x20AC","€"},
- {NULL}
- };
- char* strip_html_unicode(const char * string)
- {
- if(string == NULL) return NULL;
- char *p = (char*)string;
- // Be safe.
- size_t cpy_len = strlen(string);
- char *cpy = malloc(cpy_len + 1);
- memset(cpy,0,cpy_len+1);
- int x = 0;
- bool is_uc = false;
- while(*p)
- {
- char *sub = " ";
- is_uc = false;
- if(*p == '&')
- {
- int uit = 0;
- char uit_buf[8];
- char *p2 = p;
- // Skip silly "unwarned result" warning
- p2 = p2 + sizeof(char);
- while(*p2 && *p2 != ';')
- {
- uit_buf[uit++] = *p2++;
- }
- uit_buf[uit] = 0;
- if(*p2 == ';' && uit != 0)
- {
- int uma = 0;
- while(umap[uma] && umap[uma][0])
- {
- if(!strcmp(umap[uma][0],uit_buf))
- {
- sub = (char*)umap[uma][1];
- is_uc = true;
- p = p2;
- break;
- }
- uma++;
- }
- }
- }
- if(is_uc == false) cpy[x++] = *p;
- else while(*sub) cpy[x++] = *sub++;
- p = p + sizeof(char);
- }
- cpy[x] = '\0';
- return cpy;
- }
- int main(int argc, char *argv[])
- {
- /* Some human readable formula should be printed. */
- const char *testme = "f(x) -> ∑ ∫ √x+1 [ Ð = { |R0 } ] (Δ ≈ 0,11 +/-)";
- char *result = strip_html_unicode(testme);
- puts(result);
- if(result) free(result);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement