memory: xmemcnt(data,c,len).
squash with refactor
Squash with refactor str_to_reg.

- xrealloc instead of xmalloc/memcpy.
- Use xmemcnt/STRLEN.
fix one-off error