char tail; unsigned char skip[256]; unsigned int len = strlen(text2), longlen = strlen(text), i, x, y;
if (longlen < len) return NULL; tail = text2[len];
// 長さが1の時の対策は省略
memset(skip, (unsigned char)len, 256); for (i = 0, len--; i < len; i++) skip[(unsigned char)text2[i]] = (unsigned char)(len - i); // i = len - 1; while (i < longlen) { if (text[i] == tail) { x = i; y = len; while (text[--x] == text2[--y]) { if (y == 0) return &text[x]; } } i += skip[(unsigned char)text[i]]; } return NULL; }