MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / __URLEncode

Method __URLEncode

src/String.cpp:1027–1059  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1025static unsigned char safeChars[256];
1026
1027String String::__URLEncode() const
1028{
1029 Array<unsigned char> bytes(0,length);
1030 // utf8-encode
1031 __hxcpp_bytes_of_string(bytes,*this);
1032
1033 int extra = 0;
1034 int utf8_chars = bytes->__length();
1035 for(int i=0;i<utf8_chars;i++)
1036 if (!safeChars[bytes[i]])
1037 extra++;
1038 if (extra==0)
1039 return *this;
1040
1041 int l = utf8_chars + extra*2;
1042 char *result = hx::NewString(l);
1043 char *ptr = result;
1044
1045 for(int i=0;i<utf8_chars;i++)
1046 {
1047 if (!safeChars[bytes[i]])
1048 {
1049 static char hex[] = "0123456789ABCDEF";
1050 unsigned char b = bytes[i];
1051 *ptr++ = '%';
1052 *ptr++ = hex[ b>>4 ];
1053 *ptr++ = hex[ b & 0x0f ];
1054 }
1055 else
1056 *ptr++ = bytes[i];
1057 }
1058 return String(result,l);
1059}
1060
1061String String::toUpperCase() const
1062{

Callers

nothing calls this directly

Calls 4

__hxcpp_bytes_of_stringFunction · 0.85
NewStringFunction · 0.85
StringClass · 0.50
__lengthMethod · 0.45

Tested by

no test coverage detected