Author | Topic: CGI Interface data conversion | |
---|---|---|
Reinthaler Rudolf | CGI Interface data conversion on Fri, 23 Jan 2009 12:43:49 +0100 Hello, I have to send data to a SMS provider to the CGI interface. The Text seems to be convertet in a way like the GET method. Spaces are filled with "+" etc. Example: this+is+a+test Has anyone a functin for such conversion ? regards Rudolf | |
Thomas Braun | Re: CGI Interface data conversion on Fri, 23 Jan 2009 18:01:20 +0100 Reinthaler Rudolf wrote: > Hello, > I have to send data to a SMS provider to the CGI interface. The Text seems > to be convertet in a way like the GET method. Spaces are filled with "+" > etc. Example: this+is+a+test > Has anyone a functin for such conversion ? Hi Rodulf, of course we have regards Thomas FUNCTION URLEncode( cString, lRFC1738 ) LOCAL cSafe := "0123456789" +; Numeric "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +; Alphabetic upper "abcdefghijklmnopqrstuvwxyz" +; Alphabetic lower "-_.!~*'()" RFC2396 Mark characters LOCAL cRet := "" LOCAL nI, nLen, cChar, nChar DEFAULT lRFC1738 TO .T. nLen := LEN(cString) FOR nI := 1 TO nLen cChar := cString[nI] IF cChar == " " .AND. lRFC1738 cRet += "+" x-www-urlencoded, rather than %20 ELSEIF AT(cChar, cSafe) > 0 cRet += cChar ELSE nChar := ASC(cChar) IF nChar > 255 cRet += "+" ELSE cRet += "%" cRet += EncodeHex(nChar) ENDIF ENDIF NEXT RETURN cRet FUNCTION EncodeHex(xChar) LOCAL cRet := "", x LOCAL cChars := "0123456789ABCDEF" LOCAL l := 2 LOCAL n IF VALTYPE(xChar) = "N" n := xChar ELSE n := ASC(xChar) ENDIF DO WHILE ( n > 0 ) while we got a number... x := n%16 get modulus n := Int(n/16) remove an exponent cRet := cChars[x+1] + cRet add result to return string ENDDO l := Max(l,Len(cRet)) RETURN PADL(cRet,l,"0") lpad with zero's | |
Jose Adriano Baltieri | Re: CGI Interface data conversion on Fri, 23 Jan 2009 15:59:02 -0200 Reinthaler Rudolf wrote: > Hello, > I have to send data to a SMS provider to the CGI interface. The Text seems > to be convertet in a way like the GET method. Spaces are filled with "+" > etc. Example: this+is+a+test > Has anyone a functin for such conversion ? > regards > Rudolf > > I have an alternative Mr Rudolf. It follows below. But it depends on XBTools III funcitions (NTCOC). It's on PROduction site , that is, it works. Follows the function FUNCTION CTOLINK(LCSTR_IN) character string to be embeded on a link LOCAL LNI, ; LNT, ; LCPOS, ; LCSTR_OUT:="", ; LNPOS LNT:=LEN(LCSTR_IN) FOR LNI:=1 TO LNT LNPOS:=ASC(LCPOS:=LCSTR_IN[LNI]) IF (LNPOS >= 65 AND LNPOS <= 90) ; OR (LNPOS >= 97 AND LNPOS <= 122) ; OR (LNPOS >= 48 AND LNPOS <= 57) ; OR LCPOS IN "=&" LCSTR_OUT+=LCPOS ELSEIF LCPOS == " " LCSTR_OUT+="+" ELSEIF (LNPOS:=ASCAN(SACENTOS,{|E| LCPOS == E[1]})) > 0 LCSTR_OUT+="%" + NTOC(ASC(SACENTOS[LNPOS,3]),16,2,"0") ELSE LCSTR_OUT+="%" + NTOC(ASC(LCPOS),16,2,"0") END IF NEXT RETURN LCSTR_OUT It also needs a STATIC table (SACENTOS) that follows below. STATIC SACENTOS:={{"¡","%A1","í","¡" ,"¡"} ; ,{"¢","%A2","ó","¢" ,"¢"} ; ,{"£","%A3","ú","£" ,"£"} ; ,{"¤","%A4","ñ","¤","¤"} ; ,{"¥","%A5","Ñ","¥" ,"¥"} ; ,{"¦","%A6","ª","¦","¦"} ; ,{"§","%A7","º","§" ,"§"} ; ,{"¨","%A8","¿","¨" ,"¨"} ; ,{"©","%A9","®","©" ,"©"} ; ,{"ª","%AA","¬","ª" ,"ª"} ; ,{"«","%AB","½","«" ,"«"} ; ,{"¬","%AC","¼","¬" ,"¬"} ; ,{"","%AD","¡","­" ,""} ; ,{"®","%AE","«","®" ,"®"} ; ,{"¯","%AF","»","¯" ,"¯"} ; ,{"°","%B0","░","°" ,"°"} ; ,{"±","%B1","▒","±","±"} ; ,{"²","%B2","▓","²" ,"²"} ; ,{"³","%B3","│","³" ,"³"} ; ,{"´","%B4","┤","´" ,"´"} ; ,{"µ","%B5","Á","µ" ,"µ"} ; ,{"¶","%B6","Â","¶" ,"¶"} ; ,{"·","%B7","À","·","·"} ; ,{"¸","%B8","©","¸" ,"¸"} ; ,{"¹","%B9","╣","¹" ,"¹"} ; ,{"º","%BA","║","º" ,"º"} ; ,{"»","%BB","╗","»" ,"»"} ; ,{"¼","%BC","╝","¼","¼"} ; ,{"½","%BD","¢","½","½"} ; ,{"¾","%BE","¥","¾","¾"} ; ,{"¿","%BF","┐","¿","¿"} ; ,{"À","%C0","└","À","A"} ; ,{"Á","%C1","┴","Á","A"} ; ,{"Â","%C2","┬","Â" ,"A"} ; ,{"Ã","%C3","├","Ã","A"} ; ,{"Ä","%C4","─","Ä" ,"A"} ; ,{"Å","%C5","┼","Å" ,"A"} ; ,{"Æ","%C6","ã","Æ" ,"Æ"} ; ,{"Ç","%C7","Ã","Ç","C"} ; ,{"È","%C8","╚","È","E"} ; ,{"É","%C9","╔","É","E"} ; ,{"Ê","%CA","╩","Ê" ,"E"} ; ,{"Ë","%CB","╦","Ë" ,"E"} ; ,{"Ì","%CC","╠","Ì","I"} ; ,{"Í","%CD","═","Í","I"} ; ,{"Î","%CE","╬","Î" ,"I"} ; ,{"Ï","%CF","¤","Ï" ,"I"} ; ,{"Ð","%D0","ð","Ð" ,"Ð"} ; ,{"Ñ","%D1","Ð","Ñ","N"} ; ,{"Ò","%D2","Ê","Ò","O"} ; ,{"Ó","%D3","Ë","Ó","O"} ; ,{"Ô","%D4","È","Ô" ,"O"} ; ,{"Õ","%D5","ı","Õ","O"} ; ,{"Ö","%D6","Í","Ö" ,"O"} ; ,{"×","%D7","Î","×" ,"×"} ; ,{"Ø","%D8","Ï","Ø","Ø"} ; ,{"Ù","%D9","┘","Ù","U"} ; ,{"Ú","%DA","┌","Ú","U"} ; ,{"Û","%DB","█","Û" ,"U"} ; ,{"Ü","%DC","▄","Ü" ,"U"} ; ,{"Ý","%DD","¦","Ý","Y"} ; ,{"Þ","%DE","Ì","Þ" ,"Þ"} ; ,{"ß","%DF","▀","ß" ,"ß"} ; ,{"à","%E0","Ó","à","a"} ; ,{"á","%E1","ß","á","a"} ; ,{"â","%E2","Ô","â" ,"a"} ; ,{"ã","%E3","Ò","ã","a"} ; ,{"ä","%E4","õ","ä" ,"a"} ; ,{"å","%E5","Õ","å" ,"a"} ; ,{"æ","%E6","µ","æ" ,"æ"} ; ,{"ç","%E7","þ","ç","c"} ; ,{"è","%E8","Þ","è","e"} ; ,{"é","%E9","Ú","é","e"} ; ,{"ê","%EA","Û","ê" ,"e"} ; ,{"ë","%EB","Ù","ë" ,"e"} ; ,{"ì","%EC","ý","ì","i"} ; ,{"í","%ED","Ý","í","i"} ; ,{"î","%EE","¯","î" ,"i"} ; ,{"ï","%EF","´","ï" ,"i"} ; ,{"ð","%F0","","ð" ,"ð"} ; ,{"ñ","%F1","±","ñ","n"} ; ,{"ò","%F2","‗","ò","o"} ; ,{"ó","%F3","¾","ó","o"} ; ,{"ô","%F4","¶","ô" ,"o"} ; ,{"õ","%F5","§","õ","o"} ; ,{"ö","%F6","÷","ö" ,"o"} ; ,{"÷","%F7","¸","÷","÷"} ; ,{"ø","%F8","°","ø","ø"} ; ,{"ù","%F9","¨","ù","u"} ; ,{"ú","%FA","·","ú","u"} ; ,{"û","%FB","¹","û" ,"u"} ; ,{"ü","%FC","³","ü" ,"u"} ; ,{"ý","%FD","²","ý","y"} ; ,{"þ","%FE","■","þ" ,"þ"} ; ,{"ÿ","%FF"," ","ÿ" ,"y"} ; ,{"" ,"" ,"" ,"" ,"" } ; }, ; | |
Reinthaler Rudolf | Re: CGI Interface data conversion on Fri, 23 Jan 2009 23:56:10 +0100 Hello Thomas, Jose, many thank you both, that's what I need. Jose, your code has somthing strange that does not compile : LCPOS IN "=&" Maybe a missing include file ? regards Rudolf "Reinthaler Rudolf" <office@c-tec.at> schrieb im Newsbeitrag news:3131db60$5a15310a$11ef@news.alaska-software.com... > Hello, > I have to send data to a SMS provider to the CGI interface. The Text seems > to be convertet in a way like the GET method. Spaces are filled with "+" > etc. Example: this+is+a+test > Has anyone a functin for such conversion ? > regards > Rudolf > > | |
Jose Adriano Baltieri | Re: CGI Interface data conversion on Mon, 26 Jan 2009 11:50:40 -0200 Reinthaler Rudolf wrote: > Hello Thomas, Jose, > many thank you both, that's what I need. > Jose, your code has somthing strange that does not compile : LCPOS IN "=&" Oh no ! Sorry. It's just a DEFINE that translates $ to IN : LCPOS $ "=&" Got it ? Glad you liked it. Hope you can use it effectively ! > Maybe a missing include file ? > regards > Rudolf > > > "Reinthaler Rudolf" <office@c-tec.at> schrieb im Newsbeitrag > news:3131db60$5a15310a$11ef@news.alaska-software.com... >> Hello, >> I have to send data to a SMS provider to the CGI interface. The Text seems >> to be convertet in a way like the GET method. Spaces are filled with "+" >> etc. Example: this+is+a+test >> Has anyone a functin for such conversion ? >> regards >> Rudolf >> >> > > | |
Reinthaler Rudolf | Re: CGI Interface data conversion on Tue, 27 Jan 2009 23:01:09 +0100 Hello Jose, thank you ! helps a lot regards Rudolf "Jose Adriano Baltieri" <jabaltie@unimep.br> schrieb im Newsbeitrag news:42d73777$601cb01e$1216@news.alaska-software.com... > Reinthaler Rudolf wrote: >> Hello Thomas, Jose, >> many thank you both, that's what I need. >> Jose, your code has somthing strange that does not compile : LCPOS IN >> "=&" > > Oh no ! Sorry. It's just a DEFINE that translates $ to IN : LCPOS $ "=&" > > Got it ? > > Glad you liked it. Hope you can use it effectively ! > > >> Maybe a missing include file ? >> regards >> Rudolf >> >> >> "Reinthaler Rudolf" <office@c-tec.at> schrieb im Newsbeitrag >> news:3131db60$5a15310a$11ef@news.alaska-software.com... >>> Hello, >>> I have to send data to a SMS provider to the CGI interface. The Text >>> seems to be convertet in a way like the GET method. Spaces are filled >>> with "+" etc. Example: this+is+a+test >>> Has anyone a functin for such conversion ? >>> regards >>> Rudolf >>> >>> >> |