move some string utilities to buf_str.c to reduce some dependencies (from 0.9.8 branch).