text: /*
   * utils.h
   *
   *  Created on: 2018年6月21日
   *      Author: wanyuan.chen
   */
  
  #ifndef UTILS_H_
  #define UTILS_H_
  #include<string>
  #include<vector>
  #include<cstring>
  using namespace std;
  inline void split(const string& str, const string& separator, vector<string>& dest)
  {
      //string str = src;
      string substring;
      string::size_type start = 0, index;
      dest.clear();
      index = str.find_first_of(separator,start);
      do
      {
          if (index != string::npos)
          {
              substring = str.substr(start,index-start );
              dest.push_back(substring);
              start =index+separator.size();
              index = str.find(separator,start);
              if (start == string::npos) break;
          }
      }while(index != string::npos);
  
      //the last part
      substring = str.substr(start);
      dest.push_back(substring);
  }
  
  //定义查找表，长度256，表中的数值表示以此为起始字节的utf8字符长度
  unsigned char utf8_look_for_table[] =
  {
  
  	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  
  	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  
  	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  
  	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  
  	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  
  	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  
  	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  
  	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  
  	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  
  	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  
  	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  
  	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  
  	2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  
  	2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  
  	3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  
  	4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 1, 1
  
  };
  
  
  
  #define UTFLEN(x)  utf8_look_for_table[(x)]
  
  
  
  //计算str字符数目
  
  inline int get_utf8_length(const char *str)
  {
  
  	int clen = strlen(str);
  	int len = 0;
  
  	for(const char *ptr = str;*ptr!=0&&len<clen;
  			len++, ptr+=UTFLEN((unsigned char)*ptr));
  
  	return len;
  
  }
  
  #endif /* UTILS_H_ */
  