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

Function fxPushSubstitutionString

xs/sources/xsString.c:2006–2241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2004}
2005
2006void fxPushSubstitutionString(txMachine* the, txSlot* string, txInteger size, txInteger offset, txSlot* match, txInteger length, txInteger count, txSlot* captures, txSlot* groups, txSlot* replace)
2007{
2008 txString r;
2009 txInteger m;
2010 txInteger l;
2011 txBoolean flag;
2012 txByte c, d;
2013 txInteger i, j;
2014 txSlot* capture;
2015 txString s;
2016 r = replace->value.string;
2017 m = 0;
2018 l = 0;
2019 flag = 0;
2020 while ((c = c_read8(r++))) {
2021 if (m <= l)
2022 m = l;
2023 else
2024 fxAbort(the, XS_NOT_ENOUGH_MEMORY_EXIT);
2025 if (c == '$') {
2026 c = c_read8(r++);
2027 switch (c) {
2028 case '$':
2029 l++;
2030 flag = 1;
2031 break;
2032 case '&':
2033 l += length;
2034 flag = 1;
2035 break;
2036 case '`':
2037 l += offset;
2038 flag = 1;
2039 break;
2040 case '\'':
2041 l += size - (offset + length);
2042 flag = 1;
2043 break;
2044 case '<':
2045 if (groups && mxIsReference(groups)) {
2046 txString t = r;
2047 while ((d = c_read8(r))) {
2048 if (d == '>')
2049 break;
2050 r++;
2051 }
2052 if (d) {
2053 txInteger n = mxPtrDiff(r - t);
2054 txID name;
2055 if (n > 255)
2056 fxJump(the);
2057 c_memcpy(the->nameBuffer, t, n);
2058 the->nameBuffer[n] = 0;
2059 name = fxFindName(the, the->nameBuffer);
2060 if (name) {
2061 mxPushSlot(groups);
2062 mxGetID(name);
2063 if (!mxIsUndefined(the->stack)) {

Callers 2

Calls 5

fxJumpFunction · 0.85
fxFindNameFunction · 0.85
fxToStringFunction · 0.85
fxNewChunkFunction · 0.85
fxAbortFunction · 0.70

Tested by

no test coverage detected