void runtime·slicerunetostring(Slice b, String s) { #line 3599 "C:\Go\src\pkg\runtime\string.goc" int32 siz1, siz2, i; int32 *a; byte dum[8]; a = (int32*)b.array; siz1 = 0; for(i=0; i<b.len; i++) { siz1 += runtime·runetochar(dum, a[i]); } s = gostringsize(siz1+4); siz2 = 0; for(i=0; i<b.len; i++) { // check for race if(siz2 >= siz1) break; siz2 += runtime·runetochar(s.str+siz2, a[i]); } s.len = siz2; s.str[s.len] = 0; FLUSH(&s); }
void runtime·slicerunetostring(Slice b, String s) { s.str = 0; s.len = 0; FLUSH(&s); #line 309 "/home/14/ren/source/golang/go/src/pkg/runtime/string.goc" intgo siz1, siz2, i; int32 *a; byte dum[8]; void *pc; if(raceenabled) { pc = runtime·getcallerpc(&b); runtime·racereadrangepc(b.array, b.len*sizeof(*a), pc, runtime·slicerunetostring); } a = (int32*)b.array; siz1 = 0; for(i=0; i<b.len; i++) { siz1 += runtime·runetochar(dum, a[i]); } s = gostringsize(siz1+4); siz2 = 0; for(i=0; i<b.len; i++) { // check for race if(siz2 >= siz1) break; siz2 += runtime·runetochar(s.str+siz2, a[i]); } s.len = siz2; s.str[s.len] = 0; FLUSH(&s); }
void gkbdputc(Queue *q, int ch) { int n; Rune r; static uchar kc[5*UTFmax]; static int nk, collecting = 0; char buf[UTFmax]; r = ch; if(r == Latin) { collecting = 1; nk = 0; return; } if(collecting) { int c; nk += runetochar((char*)&kc[nk], &r); c = latin1(kc, nk); if(c < -1) /* need more keystrokes */ return; collecting = 0; if(c == -1) { /* invalid sequence */ qproduce(q, kc, nk); return; } r = (Rune)c; } n = runetochar(buf, &r); if(n == 0) return; /* if(!isdbgkey(r)) */ qproduce(q, buf, n); }
static char *convert_to_utf8(fz_context *doc, unsigned char *s, int n) { unsigned char *e = s + n; char *dst, *d; int c; if (s[0] == 0xFE && s[1] == 0xFF) { dst = d = fz_malloc(doc, n * 2); while (s + 1 < e) { c = s[0] << 8 | s[1]; d += runetochar(d, &c); s += 2; } *d = 0; return dst; } if (s[0] == 0xFF && s[1] == 0xFE) { dst = d = fz_malloc(doc, n * 2); while (s + 1 < e) { c = s[0] | s[1] << 8; d += runetochar(d, &c); s += 2; } *d = 0; return dst; } return (char*)s; }
/* Convert Unicode/PdfDocEncoding string into utf-8 */ char * pdf_to_utf8(fz_obj *src) { unsigned char *srcptr = (unsigned char *) fz_to_str_buf(src); char *dstptr, *dst; int srclen = fz_to_str_len(src); int dstlen = 0; int ucs; int i; if (srclen >= 2 && srcptr[0] == 254 && srcptr[1] == 255) { for (i = 2; i + 1 < srclen; i += 2) { ucs = srcptr[i] << 8 | srcptr[i+1]; dstlen += runelen(ucs); } dstptr = dst = fz_malloc(dstlen + 1); for (i = 2; i + 1 < srclen; i += 2) { ucs = srcptr[i] << 8 | srcptr[i+1]; dstptr += runetochar(dstptr, &ucs); } } else if (srclen >= 2 && srcptr[0] == 255 && srcptr[1] == 254) { for (i = 2; i + 1 < srclen; i += 2) { ucs = srcptr[i] | srcptr[i+1] << 8; dstlen += runelen(ucs); } dstptr = dst = fz_malloc(dstlen + 1); for (i = 2; i + 1 < srclen; i += 2) { ucs = srcptr[i] | srcptr[i+1] << 8; dstptr += runetochar(dstptr, &ucs); } } else { for (i = 0; i < srclen; i++) dstlen += runelen(pdf_doc_encoding[srcptr[i]]); dstptr = dst = fz_malloc(dstlen + 1); for (i = 0; i < srclen; i++) { ucs = pdf_doc_encoding[srcptr[i]]; dstptr += runetochar(dstptr, &ucs); } } *dstptr = '\0'; return dst; }
fz_error * pdf_toutf8(char **dstp, fz_obj *src) { unsigned char *srcptr = fz_tostrbuf(src); char *dstptr; int srclen = fz_tostrlen(src); int dstlen = 0; int ucs; int i; if (srclen > 2 && srcptr[0] == 254 && srcptr[1] == 255) { for (i = 2; i < srclen; i += 2) { ucs = (srcptr[i] << 8) | srcptr[i+1]; dstlen += runelen(ucs); } dstptr = *dstp = fz_malloc(dstlen + 1); if (!dstptr) return fz_outofmem; for (i = 2; i < srclen; i += 2) { ucs = (srcptr[i] << 8) | srcptr[i+1]; dstptr += runetochar(dstptr, &ucs); } } else { for (i = 0; i < srclen; i++) dstlen += runelen(pdf_docencoding[srcptr[i]]); dstptr = *dstp = fz_malloc(dstlen + 1); if (!dstptr) return fz_outofmem; for (i = 0; i < srclen; i++) { ucs = pdf_docencoding[srcptr[i]]; dstptr += runetochar(dstptr, &ucs); } } *dstptr = '\0'; return nil; }
char * utfrune(const char *s, Rune r) { if(r < Runeself) { return strchr(s, r); } else if(r == Runeerror) { Rune r0; int n; for(; *s != '\0'; s += n) { n = chartorune(&r0, s); if(r == r0) return (char *)s; } } else { char buf[UTFmax+1]; int n; if(!(n = runetochar(buf, &r))) return NULL; buf[n] = '\0'; return strstr(s, buf); } return NULL; }
static char * map(Rune rp[], int font) /* figure out mapping for char in this font */ { static char s[100]; char c[10]; Link *p; Rune r; if(rp[1]==0 && rp[0]<QUICK) /* fast lookup */ r = charmap[fmap[font]].quick[rp[0]]; else { /* high-valued or compound character name */ sprint(c, "%S", rp); r = 0; for (p = charmap[fmap[font]].slow; p; p = p->next) if(eq(c, p->name)){ r = p->val; break; } } if(r == 0){ /* not there */ dprint(2, "didn't find %S font# %d\n", rp, font); return 0; } dprint(2, "map %S to %s font# %d\n", rp, s, font); s[runetochar(s, &r)] = 0; return s; }
void fz_debug_text_span(fz_text_span *span) { char buf[10]; int c, n, k, i; while (span) { for (i = 0; i < span->len; i++) { c = span->text[i].c; if (c < 128) putchar(c); else { n = runetochar(buf, &c); for (k = 0; k < n; k++) putchar(buf[k]); } } if (span->eol) putchar('\n'); span = span->next; } }
char * smbstringdup(SmbHeader *h, uchar *base, uchar **bdatap, uchar *edata) { char *p; if (h && h->flags2 & SMB_FLAGS2_UNICODE) { uchar *bdata = *bdatap; uchar *savebdata; Rune r; int l; char *q; l = 0; if ((bdata - base) & 1) bdata++; savebdata = bdata; do { if (bdata + 2 > edata) return nil; r = smbnhgets(bdata); bdata += 2; l += runelen(r); } while (r != 0); p = smbemalloc(l); bdata = savebdata; q = p; do { r = smbnhgets(bdata); bdata += 2; q += runetochar(q, &r); } while (r != 0); *bdatap = bdata; return p; } return smbstrdup(bdatap, edata); }
/* * convert from latin1 to utf */ static char* fromlatin1(char *from) { char *p, *to; Rune r; if(os == Plan9) return nil; /* don't convert if we don't have to */ for(p = from; *p; p++) if(*p & 0x80) break; if(*p == 0) return nil; to = malloc(3*strlen(from)+2); if(to == nil) return nil; for(p = to; *from; from++){ r = (*from) & 0xff; p += runetochar(p, &r); } *p = 0; return to; }
/* From Plan 9 to Unix */ char* exportname(char* name) { Rune r; int nr; char *uxname; char *up; if (name == 0 || (utfrune(name, altspc) == 0 && utfrune(name,altlparen) == 0 && utfrune(name,altrparen) == 0 && utfrune(name,altamp) == 0 && utfrune(name,altquote) == 0)) return name; up = uxname = emalloc(strlen(name) + 1); names[nnames++] = uxname; while(*name != 0){ nr = chartorune(&r, name); if (r == altspc) r = ' '; if (r == altlparen) r = '('; if (r == altrparen) r = ')'; if (r == altamp) r = '&'; if (r == altquote) r = '\''; up += runetochar(up, &r); name += nr; } *up = 0; return uxname; }
void windocopy(pdfapp_t *app) { unsigned short copyucs2[16 * 1024]; char *latin1 = copylatin1; char *utf8 = copyutf8; unsigned short *ucs2; int ucs; pdfapp_oncopy(&gapp, copyucs2, 16 * 1024); for (ucs2 = copyucs2; ucs2[0] != 0; ucs2++) { ucs = ucs2[0]; utf8 += runetochar(utf8, &ucs); if (ucs < 256) *latin1++ = ucs; else *latin1++ = '?'; } *utf8 = 0; *latin1 = 0; printf("oncopy utf8=%zd latin1=%zd\n", strlen(copyutf8), strlen(copylatin1)); XSetSelectionOwner(xdpy, XA_PRIMARY, xwin, copytime); justcopied = 1; }
void fz_debug_text_span_xml(fz_text_span *span) { char buf[10]; int c, n, k, i; while (span) { printf("<span font=\"%s\" size=\"%g\" wmode=\"%d\" eol=\"%d\">\n", span->font ? span->font->name : "NULL", span->size, span->wmode, span->eol); for (i = 0; i < span->len; i++) { printf("\t<char ucs=\""); c = span->text[i].c; if (c < 128) putchar(c); else { n = runetochar(buf, &c); for (k = 0; k < n; k++) putchar(buf[k]); } printf("\" bbox=\"%d %d %d %d\" />\n", span->text[i].bbox.x0, span->text[i].bbox.y0, span->text[i].bbox.x1, span->text[i].bbox.y1); } printf("</span>\n"); span = span->next; } }
int fputrune(const Rune *r, FILE *fp) { char buf[UTFmax]; return fwrite(buf, runetochar(buf, r), 1, fp); }
void callunix(void) { int c, pid; Rune rune; char buf[512]; char *p; setnoaddr(); p = buf; while((c=getchr()) != EOF && c != '\n') if(p < &buf[sizeof(buf) - 6]) { rune = c; p += runetochar(p, &rune); } *p = 0; pid = fork(); if(pid == 0) { execlp("rc", "rc", "-c", buf, (char*)0); sysfatal("exec failed: %r"); exits("execl failed"); } waiting = 1; while(waitpid() != pid) ; waiting = 0; if(vflag) putst("!"); }
/* * Put character, possibly a rune, into read queue at interrupt time. * Called at interrupt time to process a character. */ int kbdputc(Queue *q, int ch) { int i, n; char buf[3]; Rune r; char *next; if(kbd.ir == nil) return 0; /* in case we're not inited yet */ ilock(&kbd.lockputc); /* just a mutex */ r = ch; n = runetochar(buf, &r); for(i = 0; i < n; i++){ next = kbd.iw+1; if(next >= kbd.ie) next = kbd.istage; if(next == kbd.ir) break; *kbd.iw = buf[i]; kbd.iw = next; } iunlock(&kbd.lockputc); return 0; }
/* From Unix to Plan 9 */ char* importname(char* name) { Rune r; int nr; char *up; char *p9name; if (name == 0 || (strchr(name, ' ') == 0 && strchr(name, '(') == 0 && strchr(name, ')') == 0 && strchr(name, '&') == 0 && strchr(name, '\'')== 0)) return name; p9name = emalloc(strlen(name) * 3 + 1); // worst case: all blanks + 0 up = p9name; names[nnames++] = p9name; while (*name != 0){ nr = chartorune(&r, name); if (r == ' ') r = altspc; if (r == '(') r = altlparen; if (r == ')') r = altrparen; if (r == '&') r = altamp; if (r == '\'') r = altquote; up += runetochar(up, &r); name += nr; } *up = 0; return p9name; }
static int tosnarf(Win *w, int p0, int p1) { int fd; static char buf[512]; char *c, *ce; Rune *rp, *re; if(p0 >= p1) return 0; fd = open("/dev/snarf", OWRITE|OTRUNC); if(fd < 0){ cmdprint("tosnarf: %r"); return -1; } c = buf; ce = buf + sizeof(buf); rp = w->runes + p0; re = w->runes + p1; for(; rp < re; rp++){ if(c + UTFmax > ce){ write(fd, buf, c - buf); c = buf; } c += runetochar(c, rp); } if(c > buf) write(fd, buf, c - buf); close(fd); return 0; }
void print_ss(char *s, String *a, String *b) { char *ap, *bp, *cp; Rune *rp; ap = emalloc(a->n+1); for (cp = ap, rp = a->s; *rp; rp++) cp += runetochar(cp, rp); *cp = 0; bp = emalloc(b->n+1); for (cp = bp, rp = b->s; *rp; rp++) cp += runetochar(cp, rp); *cp = 0; dprint("?warning: %s `%.*s' and `%.*s'\n", s, a->n, ap, b->n, bp); free(ap); free(bp); }
long charwidth(XftFont *f, Rune r) { char chars[UTFmax + 1] = {0}; runetochar(chars, &r); return strwidth(f, chars); }
void runeout(Rune rune) { char stoken[UTFmax+1]; int i; i = runetochar(stoken, &rune); stoken[i] = '\0'; glyphout(rune, stoken, TRUE); }
static void textpush(js_State *J, Rune c) { int n = runelen(c); if (J->lexbuf.len + n > J->lexbuf.cap) { J->lexbuf.cap = J->lexbuf.cap * 2; J->lexbuf.text = js_realloc(J, J->lexbuf.text, J->lexbuf.cap); } J->lexbuf.len += runetochar(J->lexbuf.text + J->lexbuf.len, &c); }
void compile(int eof) { Rune c; char *ep; char expbuf[ESIZE]; if((c = getchr()) == '\n') { peekc = c; c = eof; } if(c == eof) { if(!pattern) error(Q); return; } if(pattern) { free(pattern); pattern = 0; } ep = expbuf; do { if(c == '\\') { if(ep >= expbuf+sizeof(expbuf)) { error(Q); return; } ep += runetochar(ep, &c); if((c = getchr()) == '\n') { error(Q); return; } } if(ep >= expbuf+sizeof(expbuf)) { error(Q); return; } ep += runetochar(ep, &c); } while((c = getchr()) != eof && c != '\n'); if(c == '\n') peekc = c; *ep = 0; pattern = regcomp(expbuf); }
char * runetostr(char *buf, Rune *r) { char *s; for(s = buf; *r; r++) s += runetochar(s, r); *s = '\0'; return buf; }
void runtime·intstring(int64 v, String s) { #line 3581 "C:\Go\src\pkg\runtime\string.goc" s = gostringsize(8); s.len = runtime·runetochar(s.str, v); s.str[s.len] = 0; FLUSH(&s); }
void runtime·intstring(int64 v, String s) { #line 244 "/home/pi/go_build/go/src/pkg/runtime/string.goc" s = gostringsize(8); s.len = runtime·runetochar(s.str, v); s.str[s.len] = 0; FLUSH(&s); }
static void js_pushrune(js_State *J, Rune rune) { char buf[UTFmax + 1]; if (rune > 0) { buf[runetochar(buf, &rune)] = 0; js_pushstring(J, buf); } else { js_pushundefined(J); } }
void rinsert(Bufblock *buf, Rune r) { int n; n = runelen(r); if (buf->current+n > buf->end) growbuf(buf); runetochar(buf->current, &r); buf->current += n; }
/* * go from http with latin1 escapes to utf, * we assume that anything >= Runeself is already in utf */ char * httpunesc(HConnect *cc, char *s) { char *t, *v; int c; Htmlesc *e; v = halloc(cc, UTFmax*strlen(s) + 1); for(t = v; c = *s;){ if(c == '&'){ if(s[1] == '#' && s[2] && s[3] && s[4] && s[5] == ';'){ c = atoi(s+2); if(c < Runeself){ *t++ = c; s += 6; continue; } if(c < 256 && c >= 161){ e = &htmlesc[c-161]; t += runetochar(t, &e->value); s += 6; continue; } } else { for(e = htmlesc; e->name != nil; e++) if(strncmp(e->name, s, strlen(e->name)) == 0) break; if(e->name != nil){ t += runetochar(t, &e->value); s += strlen(e->name); continue; } } } *t++ = c; s++; } *t = 0; return v; }