MCPcopy Create free account
hub / github.com/3rdparty/libprocess / encode

Function encode

src/http.cpp:777–830  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

775
776
777string encode(const string& s, const string& additional_chars)
778{
779 ostringstream out;
780
781 foreach (unsigned char c, s) {
782 switch (c) {
783 // Reserved characters.
784 case '$':
785 case '&':
786 case '+':
787 case ',':
788 case '/':
789 case ':':
790 case ';':
791 case '=':
792 case '?':
793 case '@':
794 // Unsafe characters.
795 case ' ':
796 case '"':
797 case '<':
798 case '>':
799 case '#':
800 case '%':
801 case '{':
802 case '}':
803 case '|':
804 case '\\':
805 case '^':
806 case '~':
807 case '[':
808 case ']':
809 case '`':
810 // NOTE: The cast to unsigned int is needed.
811 out << '%' << std::setfill('0') << std::setw(2) << std::hex
812 << std::uppercase << (unsigned int) c;
813 break;
814 default:
815 // ASCII control characters and non-ASCII characters.
816 // NOTE: The cast to unsigned int is needed.
817 if (c < 0x20 ||
818 c > 0x7F ||
819 additional_chars.find_first_of(c) != string::npos) {
820 out << '%' << std::setfill('0') << std::setw(2) << std::hex
821 << std::uppercase << (unsigned int) c;
822 } else {
823 out << c;
824 }
825 break;
826 }
827 }
828
829 return out.str();
830}
831
832
833Try<string> decode(const string& s)

Callers 10

foreachpairFunction · 0.70
http.cppFile · 0.70
sendMethod · 0.70
MessageEncoderMethod · 0.70
HttpResponseEncoderMethod · 0.70
TEST_FFunction · 0.50
TEST_PFunction · 0.50
TEST_FFunction · 0.50
mainFunction · 0.50
TESTFunction · 0.50

Calls 13

removeFunction · 0.85
loopFunction · 0.85
readerMethod · 0.80
writerMethod · 0.80
writeMethod · 0.80
BreakFunction · 0.50
ContinueClass · 0.50
emptyMethod · 0.45
getMethod · 0.45
closeMethod · 0.45
readMethod · 0.45
sizeMethod · 0.45

Tested by 5

TEST_FFunction · 0.40
TEST_PFunction · 0.40
TEST_FFunction · 0.40
mainFunction · 0.40
TESTFunction · 0.40