static pANTLR3_UINT8 insert8 (pANTLR3_STRING string, ANTLR3_UINT32 point, const char * newbit) { ANTLR3_UINT32 len; if (point >= string->len) { return string->append(string, newbit); } len = (ANTLR3_UINT32)strlen(newbit); if (len == 0) { return string->chars; } if (string->size < (string->len + len + 1)) { string->chars = (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT32)(string->len + len + 1)); string->size = string->len + len + 1; } /* Move the characters we are inserting before, including the delimiter */ ANTLR3_MEMMOVE((void *)(string->chars + point + len), (void *)(string->chars + point), (ANTLR3_UINT32)(string->len - point + 1)); /* Note we copy the exact number of bytes */ ANTLR3_MEMMOVE((void *)(string->chars + point), newbit, (ANTLR3_UINT32)(len)); string->len += len; return string->chars; }
static pANTLR3_UINT8 appendS (pANTLR3_STRING string, pANTLR3_STRING newbit) { /* We may be passed an empty string, in which case we just return the current pointer */ if (newbit == NULL || newbit->len == 0 || newbit->size == 0 || newbit->chars == NULL) { return string->chars; } else { return string->append(string, (const char *)(newbit->chars)); } }
static pANTLR3_UINT8 insertUTF16_UTF16 (pANTLR3_STRING string, ANTLR3_UINT32 point, const char * newbit) { ANTLR3_UINT32 len; pANTLR3_UINT16 in; if (point >= string->len) { return string->append(string, newbit); } /** First, determine the length of the input string */ in = (pANTLR3_UINT16)newbit; len = 0; while (*in++ != '\0') { len++; } if (len == 0) { return string->chars; } if (string->size < (string->len + len + 1)) { string->chars = (pANTLR3_UINT8) ANTLR3_REALLOC((void *)string->chars, (ANTLR3_UINT32)(sizeof(ANTLR3_UINT16)*(string->len + len + 1))); string->size = string->len + len + 1; } /* Move the characters we are inserting before, including the delimiter */ ANTLR3_MEMMOVE((void *)(((pANTLR3_UINT16)string->chars) + point + len), (void *)(((pANTLR3_UINT16)string->chars) + point), (ANTLR3_UINT32)(sizeof(ANTLR3_UINT16)*(string->len - point + 1))); /* Note we copy the exact number of characters */ ANTLR3_MEMMOVE((void *)(((pANTLR3_UINT16)string->chars) + point), newbit, (ANTLR3_UINT32)(sizeof(ANTLR3_UINT16)*(len))); string->len += len; return string->chars; }