MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fx_serializeQueryPlus

Function fx_serializeQueryPlus

modules/data/url/url.c:1875–1957  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1873}
1874
1875void fx_serializeQueryPlus(txMachine* the, txString theSet)
1876{
1877 txString src;
1878 txInteger length;
1879 txBoolean same = 1;
1880 txInteger c;
1881 txString dst;
1882
1883 src = fxToString(the, mxArgv(0));
1884 length = 0;
1885 while (((src = mxStringByteDecode(src, &c))) && (c != C_EOF)) {
1886 if (c < 0x80) {
1887 if (c == ' ') {
1888 length += 1;
1889 same = 0;
1890 }
1891 else if (c_read8(theSet + c))
1892 length += 1;
1893 else {
1894 length += 3;
1895 same = 0;
1896 }
1897 }
1898 else {
1899 if (c < 0x800)
1900 length += 6;
1901 else if ((0xD800 <= c) && (c <= 0xDFFF))
1902 mxURIError("invalid string");
1903 else if (c < 0x10000)
1904 length += 9;
1905 else
1906 length += 12;
1907 same = 0;
1908 }
1909 }
1910 length += 1;
1911 if (same) {
1912 mxResult->value.string = mxArgv(0)->value.string;
1913 mxResult->kind = mxArgv(0)->kind;
1914 return;
1915 }
1916 mxResult->value.string = fxNewChunk(the, length);
1917 mxResult->kind = XS_STRING_KIND;
1918 src = mxArgv(0)->value.string;
1919 dst = mxResult->value.string;
1920 while (((src = mxStringByteDecode(src, &c))) && (c != C_EOF)) {
1921 if (c < 0x80) {
1922 if (c == ' ')
1923 *dst++ = '+';
1924 else if (c_read8(theSet + c))
1925 *dst++ = (char)c;
1926 else {
1927 *dst++ = '%';
1928 dst = fxStringifyHexEscape(dst, c);
1929 }
1930 }
1931 else if (c < 0x800) {
1932 *dst++ = '%';

Callers 1

fx_serializeQueryFunction · 0.85

Calls 3

fxToStringFunction · 0.85
fxNewChunkFunction · 0.85
fxStringifyHexEscapeFunction · 0.85

Tested by

no test coverage detected