public static /*STRING2*/ char *GetString(tJITCallNative *pCallNative, /*HEAP_PTR*/ byte *pThis_, uint *pLength) { tSystemString *pThis = (tSystemString *)pThis_; if (pLength != null) { *pLength = pThis->length; } return(tSystemString.GetChars(pThis)); }
public static tAsyncCall *get_Chars(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tSystemString *pThis = (tSystemString *)pThis_; uint index; char * pChars; index = (*((uint *)(pParams + 0))); pChars = tSystemString.GetChars(pThis); Sys.INTERNALCALL_RESULT_U32(pReturnValue, (uint)(pChars[index])); return(null); }
public static void DotNetStringToCString(byte *buf, uint bufLength, tSystemString *dotnetString) { uint stringLen; string monoStr; int i; monoStr = System_String.ToMonoString(dotnetString); stringLen = bufLength - 1 < (uint)monoStr.Length ? bufLength - 1 : (uint)monoStr.Length; for (i = 0; i < stringLen; i++) { buf[i] = (byte)monoStr[i]; } buf[i] = 0; }
public static tAsyncCall *InternalIndexOfAny(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tSystemString * pThis = (tSystemString *)pThis_; /*HEAP_PTR*/ byte *valueArray = (*((/*HEAP_PTR*/ byte **)(pParams + 0))); int startIndex = (*((int *)(pParams + Sys.S_PTR))); int count = (*((int *)(pParams + Sys.S_PTR + Sys.S_INT32))); uint forwards = (*((uint *)(pParams + Sys.S_PTR + Sys.S_INT32 + Sys.S_INT32))); char *pChars = tSystemString.GetChars(pThis); 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 = pChars[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); }
public static int Execute(tCLIFile *pThis, string[] args) { tThread * pThread; /*HEAP_PTR*/ byte *pArgs; int i; // Create a string array for the program arguments // Don't include the argument that is the program name. pArgs = System_Array.NewVector(Type.types[Type.TYPE_SYSTEM_ARRAY_STRING], (uint)(args.Length - 1)); Heap.MakeUndeletable(pArgs); for (i = 1; i < args.Length; i++) { tSystemString *pArgStr = System_String.FromMonoString(args[i]); System_Array.StoreElement(pArgs, (uint)(i - 1), (byte *)&pArgStr); } // Create the main application thread pThread = Thread.New(); Thread.SetEntryPoint(pThread, pThis->pMetaData, pThis->entryPoint, (byte *)&pArgs, (uint)sizeof(void *)); return(Thread.Execute()); }
public static tAsyncCall *GetHashCode(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tSystemString *pThis = (tSystemString *)pThis_; char * pChar, pEnd; int hash; hash = 0; pChar = tSystemString.GetChars(pThis); pEnd = pChar + pThis->length - 1; for (; pChar < pEnd; pChar += 2) { hash = (hash << 5) - hash + pChar[0]; hash = (hash << 5) - hash + pChar[1]; } if (pChar <= pEnd) { hash = (hash << 5) - hash + pChar[0]; } Sys.INTERNALCALL_RESULT_U32(pReturnValue, (uint)hash); return(null); }
public static tAsyncCall *InternalIndexOf(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tSystemString *pThis = (tSystemString *)pThis_; ushort value = (*((ushort *)(pParams + 0))); int startIndex = (*((int *)(pParams + Sys.S_INT32))); int count = (*((int *)(pParams + Sys.S_INT32 + Sys.S_INT32))); uint forwards = (*((uint *)(pParams + Sys.S_INT32 + Sys.S_INT32 + Sys.S_INT32))); char * pChars = tSystemString.GetChars(pThis); int lastIndex; int inc; int i; 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) { if (pChars[i] == value) { Sys.INTERNALCALL_RESULT_I32(pReturnValue, i); return(null); } } Sys.INTERNALCALL_RESULT_I32(pReturnValue, -1); return(null); }
public static string ToMonoString(tSystemString *pStr) { return(pStr != null ? H.objects[(int)((tSystemString *)pStr)->monoStr] as string : null); }
// The characters // ushort chars[0]; public static char *GetChars(tSystemString *str) { return((char *)((byte *)str + sizeof(uint))); }
public static tAsyncCall *InternalReplace(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tSystemString *pThis = (tSystemString *)pThis_; tSystemString *pOld = (*((tSystemString **)(pParams + 0))); tSystemString *pNew = (*((tSystemString **)(pParams + Sys.S_PTR))); tSystemString *pResult; uint thisLen, oldLen, newLen; char * pThisChar0, pOldChar0, pNewChar0, pResultChar0; uint i, j, replacements, dstIndex; uint resultLen; // This function (correctly) assumes that the old string is not empty thisLen = pThis->length; oldLen = pOld->length; newLen = pNew->length; pThisChar0 = tSystemString.GetChars(pThis); pOldChar0 = tSystemString.GetChars(pOld); pNewChar0 = tSystemString.GetChars(pNew); replacements = 0; for (i = 0; i < thisLen - oldLen + 1; i++) { uint match = 1; for (j = 0; j < oldLen; j++) { if (pThisChar0[i + j] != pOldChar0[j]) { match = 0; break; } } if (match != 0) { i += oldLen - 1; replacements++; } } resultLen = thisLen - (oldLen - newLen) * replacements; pResult = CreateStringHeapObj(resultLen); pResultChar0 = tSystemString.GetChars(pResult); dstIndex = 0; for (i = 0; i < thisLen; i++) { uint match = 1; if (i < thisLen - oldLen + 1) { for (j = 0; j < oldLen; j++) { match = 1; if (pThisChar0[i + j] != pOldChar0[j]) { match = 0; break; } } } else { match = 0; } if (match != 0) { Mem.memcpy(&pResultChar0[dstIndex], pNewChar0, newLen << 1); dstIndex += newLen; i += oldLen - 1; } else { pResultChar0[dstIndex++] = pThisChar0[i]; } } Sys.INTERNALCALL_RESULT_PTR(pReturnValue, pResult); return(null); }
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); }