⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 antlr3string.c

📁 ANTLR(ANother Tool for Language Recognition)它是这样的一种工具
💻 C
📖 第 1 页 / 共 3 页
字号:
    {	pANTLR3_UINT16	out;        ANTLR3_INT32    inSize;	out = (pANTLR3_UINT16)(string->chars);	inSize	= size;	while	(inSize-- > 0)	{	    *out++ = (ANTLR3_UINT16)(*ptr++);	}	/* Terminate, these strings are usually used for Token streams and printing etc.		 */	*(((pANTLR3_UINT16)(string->chars)) + size) = '\0';	string->len = size;    }    return  string;}/** Creates a new 16 bit string initialized with the 16 bit characters at the  *  supplied ptr, of pre-determined size. * \param[in] factory - Pointer to the string factory that owns the strings * \param[in] ptr - Pointer to 16 bit encoded characters * \return pointer to the new string */static    pANTLR3_STRING    newPtr16_16	(pANTLR3_STRING_FACTORY factory, pANTLR3_UINT8 ptr, ANTLR3_UINT32 size){    pANTLR3_STRING  string;    string  = factory->newSize(factory, size);    if	(string == (pANTLR3_STRING)(ANTLR3_ERR_NOMEM))    {	return	string;    }    if	(size <= 0)    {	return	string;    }    if	(ptr != NULL)    {	ANTLR3_MEMMOVE(string->chars, (const void *)ptr, (size * sizeof(ANTLR3_UINT16)));	/* Terminate, these strings are usually used for Token streams and printing etc.		 */	*(((pANTLR3_UINT16)(string->chars)) + size) = '\0';	    	string->len = size;    }    return  string;}/** Create a new 8 bit string from the supplied, null terminated, 8 bit string pointer. * \param[in] factory - Pointer to the string factory that owns strings. * \param[in] ptr - Pointer to the 8 bit encoded string * \return Pointer to the newly initialized string */static    pANTLR3_STRING    newStr8	(pANTLR3_STRING_FACTORY factory, pANTLR3_UINT8 ptr){    return factory->newPtr8(factory, ptr, (ANTLR3_UINT32)strlen((const char *)ptr));}/** Create a new 16 bit string from the supplied, null terminated, 8 bit string pointer. * \param[in] factory - Pointer to the string factory that owns strings. * \param[in] ptr - Pointer to the 8 bit encoded string * \return POinter to the newly initialized string */static    pANTLR3_STRING    newStr16_8	(pANTLR3_STRING_FACTORY factory, pANTLR3_UINT8 ptr){    return factory->newPtr8(factory, ptr, (ANTLR3_UINT32)strlen((const char *)ptr));}/** Create a new 16 bit string from the supplied, null terminated, 16 bit string pointer. * \param[in] factory - Pointer to the string factory that owns strings. * \param[in] ptr - Pointer to the 16 bit encoded string * \return Pointer to the newly initialized string */static    pANTLR3_STRING    newStr16_16	(pANTLR3_STRING_FACTORY factory, pANTLR3_UINT8 ptr){    pANTLR3_UINT16  in;    ANTLR3_UINT32   count;    /** First, determine the length of the input string     */    in	    = (pANTLR3_UINT16)ptr;    count   = 0;    while   (*in++ != '\0')    {	count++;    }    return factory->newPtr(factory, ptr, count);}static    void		    destroy	(pANTLR3_STRING_FACTORY factory, pANTLR3_STRING string){    factory->strings->del(factory->strings, string->index);}static    pANTLR3_STRING    printable8(pANTLR3_STRING_FACTORY factory, pANTLR3_STRING instr){    pANTLR3_STRING  string;        /* We don't need to be too efficient here, this is mostly for error messages and so on.     */    pANTLR3_UINT8   scannedText;    ANTLR3_UINT32   i;    /* Assume we need as much as twice as much space to parse out the control characters     */    string  = factory->newSize(factory, instr->len *2 + 1);    /* Scan through and replace unprintable (in terms of this routine)     * characters     */    scannedText = string->chars;    for	(i = 0; i < instr->len; i++)    {	if (*(instr->chars + i) == '\n')	{	    *scannedText++ = '\\';	    *scannedText++ = 'n';	}	else if (*(instr->chars + i) == '\r')	{	    *scannedText++ = '\\';	    *scannedText++ = 'r';	}	else if	(!isprint(*(instr->chars +i)))	{	    *scannedText++ = '?';	}	else	{	    *scannedText++ = *(instr->chars + i);	}    }    *scannedText  = '\0';    string->len	= (ANTLR3_UINT32)(scannedText - string->chars);        return  string;}static    pANTLR3_STRING    printable16(pANTLR3_STRING_FACTORY factory, pANTLR3_STRING instr){    pANTLR3_STRING  string;        /* We don't need to be too efficient here, this is mostly for error messages and so on.     */    pANTLR3_UINT16  scannedText;    pANTLR3_UINT16  inText;    ANTLR3_UINT32   i;    ANTLR3_UINT32   outLen;    /* Assume we need as much as twice as much space to parse out the control characters     */    string  = factory->newSize(factory, instr->len *2 + 1);    /* Scan through and replace unprintable (in terms of this routine)     * characters     */    scannedText = (pANTLR3_UINT16)(string->chars);    inText	= (pANTLR3_UINT16)(instr->chars);    outLen	= 0;    for	(i = 0; i < instr->len; i++)    {	if (*(inText + i) == '\n')	{	    *scannedText++   = '\\';	    *scannedText++   = 'n';	    outLen	    += 2;	}	else if (*(inText + i) == '\r')	{	    *scannedText++   = '\\';	    *scannedText++   = 'r';	    outLen	    += 2;	}	else if	(!isprint(*(inText +i)))	{	    *scannedText++ = '?';	    outLen++;	}	else	{	    *scannedText++ = *(inText + i);	    outLen++;	}    }    *scannedText  = '\0';    string->len	= outLen;        return  string;}static    void		    closeFactory	(pANTLR3_STRING_FACTORY factory){    /* Delete the hash table we were tracking teh strings with,this will     * causes all the allocated strings to be deallocated too     */    factory->strings->free(factory->strings);    /* Delete the space for the factory itself     */    ANTLR3_FREE((void *)factory);}static    pANTLR3_UINT8   append8	(pANTLR3_STRING string, const char * newbit){    ANTLR3_UINT32 len;    len	= (ANTLR3_UINT32)strlen(newbit);    if	(string->size < (string->len + len + 1))    {	string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT64)(string->len + len + 1));	string->size	= string->len + len + 1;    }    /* Note we copy one more byte than the strlen in order to get the trailing     */    ANTLR3_MEMMOVE((void *)(string->chars + string->len), newbit, (ANTLR3_UINT64)(len+1));    string->len	+= len;    return string->chars;}static    pANTLR3_UINT8   append16_8	(pANTLR3_STRING string, const char * newbit){    ANTLR3_UINT32   len;    pANTLR3_UINT16  apPoint;    ANTLR3_UINT32   count;    len	= (ANTLR3_UINT32)strlen(newbit);    if	(string->size < (string->len + len + 1))    {	string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT64)((sizeof(ANTLR3_UINT16)*(string->len + len + 1))));	string->size	= string->len + len + 1;    }    apPoint = ((pANTLR3_UINT16)string->chars) + string->len;    string->len	+= len;    for	(count = 0; count < len; count++)    {	*apPoint++   = *(newbit + count);    }    *apPoint = '\0';    return string->chars;}static    pANTLR3_UINT8   append16_16	(pANTLR3_STRING string, const char * newbit){    ANTLR3_UINT32 len;    pANTLR3_UINT16  in;    /** First, determine the length of the input string     */    in	    = (pANTLR3_UINT16)newbit;    len   = 0;    while   (*in++ != '\0')    {	len++;    }    if	(string->size < (string->len + len + 1))    {	string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT64)( sizeof(ANTLR3_UINT16) *(string->len + len + 1) ));	string->size	= string->len + len + 1;    }    /* Note we copy one more byte than the strlen in order to get the trailing delimiter     */    ANTLR3_MEMMOVE((void *)(((pANTLR3_UINT16)string->chars) + string->len), newbit, (ANTLR3_UINT64)(sizeof(ANTLR3_UINT16)*(len+1)));    string->len	+= len;    return string->chars;}static    pANTLR3_UINT8   set8	(pANTLR3_STRING string, const char * chars){    ANTLR3_UINT32	len;    len = (ANTLR3_UINT32)strlen(chars);    if	(string->size < len + 1)    {	string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT64)(len + 1));	string->size	= len + 1;    }    /* Note we copy one more byte than the strlen in order to get the trailing '\0'     */    ANTLR3_MEMMOVE((void *)(string->chars), chars, (ANTLR3_UINT64)(len));    string->len	    = len;    return  string->chars;}static    pANTLR3_UINT8   set16_8	(pANTLR3_STRING string, const char * chars){    ANTLR3_UINT32	len;    ANTLR3_UINT32	count;    pANTLR3_UINT16	apPoint;    len = (ANTLR3_UINT32)strlen(chars);    if	(string->size < len + 1)    {	string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT64)(sizeof(ANTLR3_UINT16)*(len + 1)));	string->size	= len + 1;    }    apPoint = ((pANTLR3_UINT16)string->chars);    string->len	= len;    for	(count = 0; count < string->len; count++)    {	*apPoint++   = *(chars + count);    }    *apPoint = '\0';    return  string->chars;}static    pANTLR3_UINT8   set16_16    (pANTLR3_STRING string, const char * chars){    ANTLR3_UINT32   len;    pANTLR3_UINT16  in;    /** First, determine the length of the input string     */    in	    = (pANTLR3_UINT16)chars;    len   = 0;    while   (*in++ != '\0')    {	len++;    }    if	(string->size < len + 1)    {	string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT64)(sizeof(ANTLR3_UINT16)*(len + 1)));	string->size	= len + 1;    }    /* Note we copy one more byte than the strlen in order to get the trailing '\0'     */    ANTLR3_MEMMOVE((void *)(string->chars), chars, (ANTLR3_UINT64)((len+1) * sizeof(ANTLR3_UINT16)));    string->len	    = len;    return  string->chars;}static    pANTLR3_UINT8   addc8	(pANTLR3_STRING string, ANTLR3_UINT32 c){    if	(string->size < string->len + 2)    {	string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT64)(string->len + 2));	string->size	= string->len + 2;    }    *(string->chars + string->len)	= (ANTLR3_UINT8)c;    *(string->chars + string->len + 1)	= '\0';    string->len++;    return  string->chars;}static    pANTLR3_UINT8   addc16	(pANTLR3_STRING string, ANTLR3_UINT32 c){    pANTLR3_UINT16  ptr;    if	(string->size < string->len + 2)    {	string->chars	= (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT64)(sizeof(ANTLR3_UINT16) * (string->len + 2)));	string->size	= string->len + 2;    }    ptr	= (pANTLR3_UINT16)(string->chars);    *(ptr + string->len)	= (ANTLR3_UINT16)c;    *(ptr + string->len + 1)	= '\0';    string->len++;    return  string->chars;}static    pANTLR3_UINT8   addi8	(pANTLR3_STRING string, ANTLR3_INT32 i){    ANTLR3_UINT8	    newbit[32];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -