U++ framework - RDF feed
type: channel
description: Do not panic. Ask here before giving up.
items: SetLineKeyValue - in memory
items: Re: SetLineKeyValue - in memory
items: Re: SetLineKeyValue - in memory: smallBugFix
items: Re: SetLineKeyValue - in memory: bugFix
items: Re: SetLineKeyValue - in memory: update
items: Re: SetLineKeyValue - in memory:update2
items: Re: SetLineKeyValue - in memory: minorBugFix

SetLineKeyValue - in memory
type: item
description: Empty lines and (// or ;) at start of line are ignored chkForEqualSign: when true - there must be '=' after key(even if it's empty) when false - line can contain only a key(withNo=), but it's added before fn returns NewLine: \n, \r and \r\n are accepted Update: -func now accepts key that has some kind of header,eg SetLineKeyValue(lines,"key","value"); while lines has somewhere 'keyAnyHdr'(eg keyLine1\nLine2=value, or key:flg:20,flg2:coffee=value) -added 2helperfuncs for pack 2vals in value - chk down code - can be used eg with WithDropChoice<EditString> bool SetLineKeyValue(String& lines,const String& key,const String& val,dword startAt=0,bool chkForEqualSign=true,dword *chkForExistanceOnly=0,String *prevBack=0){ if(!lines.GetCount())return false; ASSERT(key.GetCount()); ASSERT(startAt<lines.GetCount()); register char *p=(char*)~lines+startAt; int64 fpos; char *pst; int pos,off,linenum; if(prevBack)*prevBack=""; while(*p){ fpos=p-~lines; linenum=0;pos=0;pst=p; while(*p){if(*p=='\r'&&*p=='\n'){linenum=p-pst;break;}if(*p=='\r'||*p=='\n'){linenum=p-pst;break;}if(*p=='=')pos=p-pst; ++p;} if(*p)++p; if(linenum==0 && 0==(linenum=p-(*p?1:0)-pst))continue; if(linenum&&*pst==';'||linenum>=2&&pst[0]=='/'&&pst[1]=='/')continue; if(chkForEqualSign&&!pos)continue; if(linenum<key.GetCount()+(chkForEqualSign?1:0)||0!=memcmp(pst,~key,key.GetCount()))continue; if(prevBack&&linenum>pos/*key.GetCount()*/+1)*prevBack=lines.Mid(fpos+pos/*key.GetCount()*/+1,linenum-(/*key.GetCount()*/pos+1)); if(chkForExistanceOnly){*chkForExistanceOnly=(dword)(int32)fpos;return true;} fpos+=/*key.GetCount()*/pos+1; off=(/*key.GetCount()*/pos+1+val.GetCount())-linenum; //speedup a litle - don't insert/remove twice if(off<0)lines.Remove(fpos,abs(off)); else if(off)lines.Insert(fpos,"R",off); *(char*)lines.GetIter(fpos-1)='='; memcpy((void*)lines.GetIter(fpos),~val,val.GetCount()); return true; } /* StringStream ss(lines); while(!ss.IsEof()){ fpos=ss.GetPos(); line=ss.GetLine();if(chkForEqualSign&&-1==(pos…
creator: luoganda
date: 2017-04-21T15:55:06-00:00

Re: SetLineKeyValue - in memory
type: item
description: These can be used when info is known to be contignous, errline is just an errorlike func PromptOK can be used instead of it All are readOnly funcs inline bool SLKVSkipEmpty(StringStream &ss){ bool is=0; while(!ss.IsEof()&&(ss.Peek()=='\n'||ss.Peek()=='\r'||ss.Peek()==';'||*(word*)ss.PeekPtr(2)==*(word*)"//")){ is=1;ss.GetLine(); } return is; } inline String SLKVKey(StringStream &ss,bool withEqSign=true){ String ln=ss.GetLine(); int i=ln.Find('=');if(i==-1){if(withEqSign){errline(el,"char '=' not found near %s",~ln);return String::GetVoid();}}else ln=ln.Mid(0,i); return ln; } inline String SLKVValue(StringStream &ss){ String ln=ss.GetLine(); int i=ln.Find('=');if(i==-1){errline(el,"char '=' not found near %s",~ln);return String::GetVoid();} return ln.Mid(i+1); } inline bool SLKVKeyValue(StringStream &ss,String& key,String& val,bool withEqSign=true){ key=val="";String ln=ss.GetLine(); int i=ln.Find('=');if(i==-1){if(withEqSign){errline(el,"char '=' not found near %s",~ln);return false;}key=ln;return true;} key=ln.Mid(0,i); val=ln.Mid(i+1); return true; }
creator: luoganda
date: 2017-04-24T08:42:24-00:00

Re: SetLineKeyValue - in memory: smallBugFix
type: item
description: Modified upper SLKVKey(from ln.Mid(i) to ln.Mid(0,i)) now returns right result...
creator: luoganda
date: 2017-04-25T19:43:31-00:00

Re: SetLineKeyValue - in memory: bugFix
type: item
description: SetLineKeyValue, now returns right result...
creator: luoganda
date: 2017-04-25T23:21:46-00:00

Re: SetLineKeyValue - in memory: update
type: item
description: update -> check original message
creator: luoganda
date: 2017-04-30T11:25:00-00:00

Re: SetLineKeyValue - in memory:update2
type: item
description: Using SetLineKeyValue with StringStream: -StringStream: a few funcs should be added to use this,chk down If you read this, there was also original func update - chk original message Usage: -to speedup and data(lines) is/are known to be contignous,then; SetLineKeyValue(ss,"a key","a value"); ss.GetLine(); //advance pos to next line,so next is found immediatelly -when keys(data) is not known to be contignous(butAreSearchable),then; SetLineKeyValue(ss,"a key","a value"); //just this bool SetLineKeyValue(StringStream& ss,const String& key,const String& val,bool chkForEqualSign,dword *chkForExistanceOnly,String *prevBack){ if(ss.IsEof())return false; register char *p=(char*)ss.PeekPtr(); int64 fpos=ss.GetPos();ss.Seek(0); char *pst,*porg=p,*ssSt=(char*)ss.PeekPtr(); int pos,off,linenum; ss.Seek(fpos); if(prevBack)*prevBack=""; while(*p){ fpos=ss.GetPos(); linenum=0;pos=0;pst=p; while(*p){if(*p=='\r'&&*p=='\n'){linenum=p-pst/*p-~lines-fpos*/;break;}if(*p=='\r'||*p=='\n'){linenum=p-pst/*p-~lines-fpos*/;break;}if(*p=='=')pos=p-pst/*p-~lines-fpos*/; ++p;} if(*p!=0)++p; if(linenum==0 && 0==(linenum=p-(*p?1:0)-pst/*~lines-fpos*/))continue; if(linenum&&*pst==';'||linenum>=2&&pst[0]=='/'&&pst[1]=='/')continue; if(chkForEqualSign&&!pos)continue; if(linenum<key.GetCount()+(chkForEqualSign?1:0)||0!=memcmp(pst,~key,key.GetCount()))continue;if(chkForEqualSign&&pst[key.GetCount()]!='=')continue; if(prevBack&&linenum>fpos+/*key.GetCount()*/pos+1)*prevBack=String(pst+/*key.GetCount()*/pos+1/*lines.Mid(fpos+key.GetCount()+1*/,linenum-(/*key.GetCount()*/pos+1)); if(chkForExistanceOnly){*chkForExistanceOnly=(dword)(int32)fpos;return true;} fpos+=/*key.GetCount()*/pos+1; off=(/*key.GetCount()*/pos+1+val.GetCount())-linenum; //speedup a litle - don't insert/remove twice if(off<0)ss.Remove(abs(off),fpos); else if(off)ss.Insert('R',off,fpos); *(char*)ss.GetIter(fpos-1)='='; memcpy((void*)ss.GetIter(fpos),~val,val.GetCount()); //if(off<0)slns. lines.Remove(fpos,abs(off)); else if(off)lines.Inse…
creator: luoganda
date: 2017-04-30T12:33:53-00:00

Re: SetLineKeyValue - in memory: minorBugFix
type: item
description: prevBack sometimes returned empty string - even when there was a value, chk original message
creator: luoganda
date: 2017-05-01T18:55:14-00:00