Skip to content

Commit

Permalink
Compress integer to string
Browse files Browse the repository at this point in the history
Part of #40
  • Loading branch information
phase committed Nov 23, 2015
1 parent 877b231 commit b8afcce
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions o.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(p<o->s.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

This comment has been minimized.

Copy link
@refi64

refi64 Nov 24, 2015

Collaborator

@phase Should I add a function newosc to create a string object from a single character? It's starting to feel like a common occurrence now...

This comment has been minimized.

Copy link
@phase

phase Nov 24, 2015

Author Owner

Yes please! That's like the third time I've done it 😞


S exc(C c){
static S psb; //string buffer
static S pcbb; //codeblock buffer
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b8afcce

Please sign in to comment.