Esempio n. 1
0
        public static tAsyncCall *InternalIndexOfAny(tJITCallNative *pCallNative, byte *pThis, byte *pParams, byte *pReturnValue)
        {
            /*HEAP_PTR*/ byte *valueArray;
            int    startIndex, count;
            uint   forwards;
            string s;

            s          = ToMonoString((tSystemString *)pThis);
            valueArray = (*((/*HEAP_PTR*/ byte **)(pParams + 0)));
            startIndex = (*((int *)(pParams + Sys.S_PTR)));
            count      = (*((int *)(pParams + Sys.S_PTR + Sys.S_INT32)));
            forwards   = (*((uint *)(pParams + Sys.S_PTR + Sys.S_INT32 + Sys.S_INT32)));

            byte *valueChars    = System_Array.GetElements(valueArray);
            uint  numValueChars = System_Array.GetLength(valueArray);

            int lastIndex;
            int inc;
            int i, j;

            if (forwards != 0)
            {
                lastIndex = startIndex + count;
                inc       = 1;
                i         = startIndex;
            }
            else
            {
                lastIndex = startIndex - 1;
                inc       = -1;
                i         = startIndex + count - 1;
            }
            for (; i != lastIndex; i += inc)
            {
                char thisChar = s[i];
                for (j = (int)numValueChars - 1; j >= 0; j--)
                {
                    if (thisChar == ((ushort *)valueChars)[j])
                    {
                        Sys.INTERNALCALL_RESULT_I32(pReturnValue, i);
                        return(null);
                    }
                }
            }
            Sys.INTERNALCALL_RESULT_I32(pReturnValue, -1);
            return(null);
        }
Esempio n. 2
0
        public static tAsyncCall *InternalTrim(tJITCallNative *pCallNative, byte *pThis, byte *pParams, byte *pReturnValue)
        {
            /*HEAP_PTR*/ byte *pWhiteChars;
            uint           trimType, i, checkCharsLen;
            string         s, ret;
            char *         pCheckChars;
            tSystemString *pRet;

            pWhiteChars = (*((/*HEAP_PTR*/ byte **)(pParams + 0)));
            char[] whiteChars = null;
            if (pWhiteChars != null)
            {
                pCheckChars   = (char *)System_Array.GetElements(pWhiteChars);
                checkCharsLen = System_Array.GetLength(pWhiteChars);
                whiteChars    = new char[checkCharsLen];
                for (i = 0; i < checkCharsLen; i++)
                {
                    whiteChars[i] = pCheckChars[i];
                }
            }
            trimType = (*((uint *)(pParams + Sys.S_PTR)));

            s   = ToMonoString((tSystemString *)pThis);
            ret = null;

            if (trimType == 1)
            {
                ret = s.TrimStart(whiteChars);
            }
            else if (trimType == 2)
            {
                ret = s.TrimEnd(whiteChars);
            }
            else if (trimType == 3)
            {
                ret = s.Trim(whiteChars);
            }

            pRet = FromMonoString(ret);

            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pRet);

            return(null);
        }
Esempio n. 3
0
        public static tAsyncCall *InternalTrim(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue)
        {
            tSystemString *    pThis = (tSystemString *)pThis_;
            /*HEAP_PTR*/ byte *pWhiteChars;
            uint           trimType, i, j, checkCharsLen;
            uint           ofsStart, ofsEnd;
            ushort *       pCheckChars;
            uint           isWhiteSpace;
            tSystemString *pRet;
            ushort         c;
            char *         pChars, pRetChars;

            pWhiteChars   = (*((/*HEAP_PTR*/ byte **)(pParams + 0)));
            trimType      = (*((uint *)(pParams + Sys.S_PTR)));
            pCheckChars   = (ushort *)System_Array.GetElements(pWhiteChars);
            checkCharsLen = System_Array.GetLength(pWhiteChars);

            ofsStart = 0;
            ofsEnd   = pThis->length;
            pChars   = tSystemString.GetChars(pThis);
            if ((trimType & 1) != 0)
            {
                // Trim start
                for (i = ofsStart; i < ofsEnd; i++)
                {
                    // Check if each char is in the array
                    isWhiteSpace = 0;
                    c            = pChars[i];
                    for (j = 0; j < checkCharsLen; j++)
                    {
                        if (c == pCheckChars[j])
                        {
                            isWhiteSpace = 1;
                            break;
                        }
                    }
                    if (isWhiteSpace == 0)
                    {
                        ofsStart = i;
                        break;
                    }
                }
            }
            if ((trimType & 2) != 0)
            {
                // Trim end
                for (i = ofsEnd - 1; i >= ofsStart; i--)
                {
                    // Check if each char is in the array
                    isWhiteSpace = 0;
                    c            = pChars[i];
                    for (j = 0; j < checkCharsLen; j++)
                    {
                        if (c == pCheckChars[j])
                        {
                            isWhiteSpace = 1;
                            break;
                        }
                    }
                    if (isWhiteSpace == 0)
                    {
                        ofsEnd = i + 1;
                        break;
                    }
                }
            }

            pRet      = CreateStringHeapObj(ofsEnd - ofsStart);
            pRetChars = tSystemString.GetChars(pRet);
            Mem.memcpy(pRetChars, &pChars[ofsStart], (SIZE_T)((ofsEnd - ofsStart) << 1));
            Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pRet);

            return(null);
        }