rendered paste bodychar*XmlNormalizeString(xmlChar **utf){ unsigned char *utfp, *iso; const char *start, *end, *pointer; char *tmpin = NULL, *tmp = NULL; int tlen, size, out_size, temp, ret; int dblspace = 0; start = end = pointer = NULL; utfp = *utf; size = (int)strlen((char*)utfp)+1; out_size = size*2-1; iso = malloc(out_size); check(iso); memset(iso, 0, out_size); temp=size; ret = UTF8Toisolat1(iso, &out_size, utfp, &temp); if (ret < 0) { if (ret == -1) { printf(_("unknown transcoding error\n")); }else if (ret == -2) { printf(_("UTF8Toisolat1 transcoding error\n")); }else printf(_("UTF8Toisolat1 transcoding failed\n")); } xmlFree(utfp); tmpin = malloc((int)strlen((char*)iso)+1); check(tmpin); memset(tmpin, 0, strlen((char*)iso)+1); memcpy(tmpin, iso, strlen((char*)iso)); free(iso); start = end = tmpin; while (*start != 0 && isspace(*start)) start++; while (*end != 0) end++; end--; while (end > start && isspace(*end)) end--; end++; /* check for double-spaces existence, and if so, count them up */ pointer = start; while (pointer < end) { if (isspace(*pointer)) { pointer++; if (isspace(*pointer)) { while(isspace(*pointer)) { dblspace++; pointer++; } } } pointer++; } if (start == tmpin) { /* not leading white-spaces */ if (end == (start + strlen(tmpin))) { /* nor trailing either */ if (dblspace==0) { return tmpin; } } } tlen = ((end - start) - dblspace) + 1; tmp = malloc(tlen); check(tmp); memset(tmp, 0, tlen); pointer = tmp; while(start < end) { if (isspace(*start)) { memcpy((char*)pointer, " ", 1); pointer++; start++; if (isspace(*start)) while(isspace(*start)) start++; }else{ if((!isspace(*start)) || (!isblank(*start))) { memcpy((char*)pointer, start, 1); pointer++; } start++; } } free(tmpin); return (char*)tmp;} /* XmlNormalizeString */