From b8afccefbad30bbdc9abe25a5457aa235cc37296 Mon Sep 17 00:00:00 2001 From: phase Date: Mon, 23 Nov 2015 15:47:32 -0800 Subject: [PATCH] Compress integer to string Part of #40 --- o.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/o.c b/o.c index 31aa9c4..a7ec8e1 100644 --- a/o.c +++ b/o.c @@ -220,6 +220,8 @@ C pec(C c){static C em[]="abtnvf";S p;if(p=strchr(em,c))R 0x7+(p-em);else R c;} V toca(ST st,O o){ST ca=newst(o->s.z+1);I p=0;while(ps.z){C c[2]={o->s.s[p],0};psh(ca,newos(c,1));p++;}psh(st,newoa(ca));dlo(o);} //string to char array +V cmprs(ST st,O o){C c[2]={o->d,0};psh(st,newos(c,1));dlo(o);} //compress string to array + S exc(C c){ static S psb; //string buffer static S pcbb; //codeblock buffer @@ -284,6 +286,7 @@ S exc(C c){ case 'j':psh(st,newod(rdlnd()));BK; //read number case 'l':psh(st,newod(len(st)));BK; //push length case '~':eval(st);BK; //eval + case 'c':cmprs(st,pop(st));BK; //compress int to string case 's':toca(st,pop(st));BK; //string to char array case 'S':psh(st,newos("",0));BK; //blank string case 'T':psh(st,newos(" ",1));BK; //string w/ space