use multi-byte safe substr for user agent string