Alaska Software Inc. - CGI Interface data conversion
Username: Password:
AuthorTopic: CGI Interface data conversion
Reinthaler RudolfCGI 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","í","&iexcl;" ,"¡"} ;
                  ,{"¢","%A2","ó","&cent;"  ,"¢"} ;
                  ,{"£","%A3","ú","&pound;" ,"£"} ;
                  ,{"¤","%A4","ñ","&curren;","¤"} ;
                  ,{"¥","%A5","Ñ","&yen;"   ,"¥"} ;
                  ,{"¦","%A6","ª","&brvbar;","¦"} ;
                  ,{"§","%A7","º","&sect;"  ,"§"} ;
                  ,{"¨","%A8","¿","&uml;"   ,"¨"} ;
                  ,{"©","%A9","®","&copy;"  ,"©"} ;
                  ,{"ª","%AA","¬","&ordf;"  ,"ª"} ;
                  ,{"«","%AB","½","&laquo;" ,"«"} ;
                  ,{"¬","%AC","¼","&not;"   ,"¬"} ;
                  ,{"­","%AD","¡","&shy;"   ,"­"} ;
                  ,{"®","%AE","«","&reg;"   ,"®"} ;
                  ,{"¯","%AF","»","&macr;"  ,"¯"} ;
                  ,{"°","%B0","░","&deg;"   ,"°"} ;
                  ,{"±","%B1","▒","&plusmn;","±"} ;
                  ,{"²","%B2","▓","&sup2;"  ,"²"} ;
                  ,{"³","%B3","│","&sup3;"  ,"³"} ;
                  ,{"´","%B4","┤","&acute;" ,"´"} ;
                  ,{"µ","%B5","Á","&micro;" ,"µ"} ;
                  ,{"¶","%B6","Â","&para;"  ,"¶"} ;
                  ,{"·","%B7","À","&middot;","·"} ;
                  ,{"¸","%B8","©","&cedil;" ,"¸"} ;
                  ,{"¹","%B9","╣","&sup1;"  ,"¹"} ;
                  ,{"º","%BA","║","&ordm;"  ,"º"} ;
                  ,{"»","%BB","╗","&raquo;" ,"»"} ;
                  ,{"¼","%BC","╝","&frac14;","¼"} ;
                  ,{"½","%BD","¢","&frac12;","½"} ;
                  ,{"¾","%BE","¥","&frac34;","¾"} ;
                  ,{"¿","%BF","┐","&iquest;","¿"} ;
                  ,{"À","%C0","└","&Agrave;","A"} ;
                  ,{"Á","%C1","┴","&Aacute;","A"} ;
                  ,{"Â","%C2","┬","&Acirc;" ,"A"} ;
                  ,{"Ã","%C3","├","&Atilde;","A"} ;
                  ,{"Ä","%C4","─","&Auml;"  ,"A"} ;
                  ,{"Å","%C5","┼","&Aring;" ,"A"} ;
                  ,{"Æ","%C6","ã","&AElig;" ,"Æ"} ;
                  ,{"Ç","%C7","Ã","&Ccedil;","C"} ;
                  ,{"È","%C8","╚","&Egrave;","E"} ;
                  ,{"É","%C9","╔","&Eacute;","E"} ;
                  ,{"Ê","%CA","╩","&Ecirc;" ,"E"} ;
                  ,{"Ë","%CB","╦","&Euml;"  ,"E"} ;
                  ,{"Ì","%CC","╠","&Igrave;","I"} ;
                  ,{"Í","%CD","═","&Iacute;","I"} ;
                  ,{"Î","%CE","╬","&Icirc;" ,"I"} ;
                  ,{"Ï","%CF","¤","&Iuml;"  ,"I"} ;
                  ,{"Ð","%D0","ð","&ETH;"   ,"Ð"} ;
                  ,{"Ñ","%D1","Ð","&Ntilde;","N"} ;
                  ,{"Ò","%D2","Ê","&Ograve;","O"} ;
                  ,{"Ó","%D3","Ë","&Oacute;","O"} ;
                  ,{"Ô","%D4","È","&Ocirc;" ,"O"} ;
                  ,{"Õ","%D5","ı","&Otilde;","O"} ;
                  ,{"Ö","%D6","Í","&Ouml;"  ,"O"} ;
                  ,{"×","%D7","Î","&times;" ,"×"} ;
                  ,{"Ø","%D8","Ï","&Oslash;","Ø"} ;
                  ,{"Ù","%D9","┘","&Ugrave;","U"} ;
                  ,{"Ú","%DA","┌","&Uacute;","U"} ;
                  ,{"Û","%DB","█","&Ucirc;" ,"U"} ;
                  ,{"Ü","%DC","▄","&Uuml;"  ,"U"} ;
                  ,{"Ý","%DD","¦","&Yacute;","Y"} ;
                  ,{"Þ","%DE","Ì","&THORN;" ,"Þ"} ;
                  ,{"ß","%DF","▀","&szlig;" ,"ß"} ;
                  ,{"à","%E0","Ó","&agrave;","a"} ;
                  ,{"á","%E1","ß","&aacute;","a"} ;
                  ,{"â","%E2","Ô","&acirc;" ,"a"} ;
                  ,{"ã","%E3","Ò","&atilde;","a"} ;
                  ,{"ä","%E4","õ","&auml;"  ,"a"} ;
                  ,{"å","%E5","Õ","&aring;" ,"a"} ;
                  ,{"æ","%E6","µ","&aelig;" ,"æ"} ;
                  ,{"ç","%E7","þ","&ccedil;","c"} ;
                  ,{"è","%E8","Þ","&egrave;","e"} ;
                  ,{"é","%E9","Ú","&eacute;","e"} ;
                  ,{"ê","%EA","Û","&ecirc;" ,"e"} ;
                  ,{"ë","%EB","Ù","&euml;"  ,"e"} ;
                  ,{"ì","%EC","ý","&igrave;","i"} ;
                  ,{"í","%ED","Ý","&iacute;","i"} ;
                  ,{"î","%EE","¯","&icirc;" ,"i"} ;
                  ,{"ï","%EF","´","&iuml;"  ,"i"} ;
                  ,{"ð","%F0","­","&eth;"   ,"ð"} ;
                  ,{"ñ","%F1","±","&ntilde;","n"} ;
                  ,{"ò","%F2","‗","&ograve;","o"} ;
                  ,{"ó","%F3","¾","&oacute;","o"} ;
                  ,{"ô","%F4","¶","&ocirc;" ,"o"} ;
                  ,{"õ","%F5","§","&otilde;","o"} ;
                  ,{"ö","%F6","÷","&ouml;"  ,"o"} ;
                  ,{"÷","%F7","¸","&divide;","÷"} ;
                  ,{"ø","%F8","°","&oslash;","ø"} ;
                  ,{"ù","%F9","¨","&ugrave;","u"} ;
                  ,{"ú","%FA","·","&uacute;","u"} ;
                  ,{"û","%FB","¹","&ucirc;" ,"u"} ;
                  ,{"ü","%FC","³","&uuml;"  ,"u"} ;
                  ,{"ý","%FD","²","&yacute;","y"} ;
                  ,{"þ","%FE","■","&thorn;" ,"þ"} ;
                  ,{"ÿ","%FF"," ","&yuml;"  ,"y"} ;
                  ,{"" ,""   ,"" ,""        ,"" } ;
                 }, ;
Reinthaler RudolfRe: 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 RudolfRe: 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
>>>
>>>
>>