#include "lib.h" char SPLITER[] = " \t\n\r~!@#$%^&*()_+{}:\"<>?-=[]|\\;',./"; char SPACE[] = " \t\n\r"; char ALPHA[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; char DIGIT[] = "0123456789"; char NAME_CHAR[] = "_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 記憶體配置函數 int newMemoryCount = 0; void* newMemory(int size) { void *ptr=malloc(size); assert(ptr != NULL); memset(ptr, 0, size); // printf("memGet:%p\n", ptr); newMemoryCount++; return ptr; } int freeMemoryCount=0; void freeMemory(void *ptr) { // printf("memFree:%p\n", ptr); free(ptr); freeMemoryCount++; } void checkMemory() { printf("newMemoryCount=%d freeMemoryCount=%d\n", newMemoryCount, freeMemoryCount); } // 檔案輸出入 BYTE* newFileBytes(char *fileName, int *sizePtr) { FILE *file = fopen(fileName, "rb"); fseek(file, 0 , SEEK_END); long size = ftell(file); rewind(file); BYTE *buffer = (char*) newMemory(size+1); fread (buffer,size,1,file); fclose(file); *sizePtr = size; return buffer; } char* newFileStr(char *fileName) { int size; BYTE *buffer = newFileBytes(fileName, &size); buffer[size] = '\0'; return (char*) buffer; } char *newStr(char *str) { char *rzStr = newMemory(strlen(str)+1); strcpy(rzStr, str); return rzStr; } char *newSubstr(char *str, int i, int len) { char *rzStr = newMemory(len+1); strSubstr(rzStr, str, i, len); return rzStr; } // 字串函數 void strPrint(void *data) { printf("%s ", data); } void strPrintln(void *data) { printf("%s\n", data); } BOOL strHead(char *str, char *head) { return (strncmp(str, head, strlen(head))==0); } BOOL strTail(char *str, char *tail) { int strLen = strlen(str), tailLen = strlen(tail); if (strLen < tailLen) return FALSE; return (strcmp(str+strLen-tailLen, tail)==0); } int strCountChar(char *str, char *charSet) { int i, count=0; for (i=0; i str && strMember(*stop, set); stop--); if (start <= stop) { strncpy(trimStr, start, stop-start+1); trimStr[stop-start+1]='\0'; } else strcpy(trimStr, ""); } void strReplace(char *str, char *from, char to) { int i; for (i=0; i