Exemplo n.º 1
0
void SHTokenizeW( 
	const wstring& target, 
	vector<wstring>& tokens, 
	const wstring &delim 
	)
{
	wstring::size_type lastPos = target.find_first_not_of( delim );
	wstring::size_type pos = target.find_first_of( delim, lastPos );

	while( wstring::npos != pos || wstring::npos != lastPos )
	{
		tokens.push_back( target.substr(lastPos, pos - lastPos) );
		lastPos = target.find_first_not_of( delim, pos );
		pos = target.find_first_of( delim, lastPos );
	}
}
Exemplo n.º 2
0
/* static */
void ConfigFile::trim( wstring& s )
{
	// Remove leading and trailing whitespace
	static const wchar_t whitespace[] = L" \n\t\v\r\f";
	s.erase( 0, s.find_first_not_of(whitespace) );
	s.erase( s.find_last_not_of(whitespace) + 1U );
}
Exemplo n.º 3
0
static void string_strip(wstring& s)
{
    static const wchar_t* empties = L" \t\n\r";
    int e = s.find_last_not_of(empties);
    s.erase(e + 1);
    int b = s.find_first_not_of(empties);
    s.erase(0,b);
}
Exemplo n.º 4
0
void LTrim( wstring& wsInOut )
{
	size_t nPos = wsInOut.find_first_not_of(L" \n\r\t");
	if (nPos!= wstring::npos)
	{
		wsInOut = wsInOut.substr(nPos); 
	}
}
Exemplo n.º 5
0
size_t Tokenize(const wstring& str, const wstring& delimiters,
                vector<wstring>& tokens) {
  tokens.clear();

  size_t index_begin = str.find_first_not_of(delimiters);

  while (index_begin != wstring::npos) {
    size_t index_end = str.find_first_of(delimiters, index_begin + 1);
    if (index_end == wstring::npos) {
      tokens.push_back(str.substr(index_begin));
      break;
    } else {
      tokens.push_back(str.substr(index_begin, index_end - index_begin));
      index_begin = str.find_first_not_of(delimiters, index_end + 1);
    }
  }

  return tokens.size();
}
void trim(wstring& str) {
    wstring::size_type pos = str.find_last_not_of(' ');
    if(pos != string::npos) {
        str.erase(pos + 1);
        pos = str.find_first_not_of(' ');
        if(pos != string::npos) 
            str.erase(0, pos);
    }
    else 
        str.erase(str.begin(), str.end());
}
Exemplo n.º 7
0
wstring StringUtility::Trim(const wstring& wstr)
{
    const wchar_t* WHITE_SPACES = L" \t";

    wstring result;
    wstring::size_type left = wstr.find_first_not_of(WHITE_SPACES);
    if (left != wstring::npos)
    {
        wstring::size_type right = wstr.find_last_not_of(WHITE_SPACES);
        result = wstr.substr(left, right - left + 1);
    }

    return FilterQuotations(result);
}
Exemplo n.º 8
0
void Trim(wstring& str, const wchar_t trim_chars[],
          bool trim_left, bool trim_right) {
  if (str.empty())
    return;

  const size_t index_begin =
      trim_left ? str.find_first_not_of(trim_chars) : 0;
  const size_t index_end =
      trim_right ? str.find_last_not_of(trim_chars) : str.length() - 1;

  if (index_begin == wstring::npos || index_end == wstring::npos) {
    str.clear();
    return;
  }

  if (trim_right)
    str.erase(index_end + 1, str.length() - index_end + 1);
  if (trim_left)
    str.erase(0, index_begin);
}
Exemplo n.º 9
0
void OIFReader::ReadOifLine(wstring oneline)
{
   //process
   if (oneline.substr(0, 6) == L"[Axis ")
   {
      axis_num++;
   }
   else
   {
      if (axis_num > -1)
      {
         size_t pos = oneline.find(L'=');
         wstring str1 = oneline.substr(0, oneline.find_last_not_of(L' ', pos));
         wstring str2 = oneline.substr(oneline.find_first_not_of(L' ', pos+1));

         if (str1 == L"AxisCode")
         {
            if (cur_axis != axis_num)
            {
               cur_axis = axis_num;
               axis_code.clear();
               pix_unit.clear();
               max_size.clear();
               start_pos.clear();
               end_pos.clear();
            }
            axis_code = str2;
         }
         else if (str1 == L"PixUnit")
         {
            if (cur_axis != axis_num)
            {
               cur_axis = axis_num;
               axis_code.clear();
               pix_unit.clear();
               max_size.clear();
               start_pos.clear();
               end_pos.clear();
            }
            pix_unit = str2;
         }
         else if (str1 == L"MaxSize")
         {
            if (cur_axis != axis_num)
            {
               cur_axis = axis_num;
               axis_code.clear();
               pix_unit.clear();
               max_size.clear();
               start_pos.clear();
               end_pos.clear();
            }
            max_size = str2;
         }
         else if (str1 == L"StartPosition")
         {
            if (cur_axis != axis_num)
            {
               cur_axis = axis_num;
               axis_code.clear();
               pix_unit.clear();
               max_size.clear();
               start_pos.clear();
               end_pos.clear();
            }
            start_pos = str2;
         }
         else if (str1 == L"EndPosition")
         {
            if (cur_axis != axis_num)
            {
               cur_axis = axis_num;
               axis_code.clear();
               pix_unit.clear();
               max_size.clear();
               start_pos.clear();
               end_pos.clear();
            }
            end_pos = str2;
         }
      }
   }
   if (oneline.substr(0, 9) == L"[Channel ")
   {
	  light_type.clear();
      chan_num++;
   }
   else
   {
      if (chan_num > -1)
      {
         size_t pos = oneline.find(L'=');
         wstring str1 = oneline.substr(0, oneline.find_last_not_of(L' ', pos));
         wstring str2 = oneline.substr(oneline.find_first_not_of(L' ', pos+1));
		 wstring str3 = L"Transmitted Light";
		 if (str1 == L"LightType") {
			 light_type = str2;
			 if (light_type.find(str3) != wstring::npos) {
				 for (int i = m_excitation_wavelength_list.size() -1; i >=0; i--) {
					 if (m_excitation_wavelength_list.at(i).chan_num == cur_chan) {
						 m_excitation_wavelength_list.at(i).wavelength = -1;
						 break;
					 }
				 }
			 }
		  }
         else if (str1 == L"ExcitationWavelength")
         {
            if (cur_chan != chan_num)
            {
               cur_chan = chan_num;
               WavelengthInfo info;
               info.chan_num = cur_chan;
               info.wavelength = WSTOD(str2);
				if (light_type == L"Transmitted Light") 
					info.wavelength = -1;
               m_excitation_wavelength_list.push_back(info);
            }
         }
      }
   }

   //axis
   if (!axis_code.empty() &&
         !pix_unit.empty() &&
         !max_size.empty() &&
         !start_pos.empty() &&
         !end_pos.empty())
   {
      //calculate
      double spc = 0.0;
      double dmax = WSTOD(max_size);
      if (dmax > 0.0)
         spc= fabs((WSTOD(end_pos)-
                  WSTOD(start_pos)))/
            dmax;
      if ((int64_t)pix_unit.find(L"nm")!=-1)
         spc /= 1000.0;
      if ((int64_t)axis_code.find(L"X")!=-1)
      {
         m_x_size = WSTOI(max_size);
         m_xspc = spc;
      }
      else if ((int64_t)axis_code.find(L"Y")!=-1)
      {
         m_y_size = WSTOI(max_size);
         m_yspc = spc;
      }
      else if ((int64_t)axis_code.find(L"Z")!=-1)
         m_zspc = spc;

      axis_code.clear();
      pix_unit.clear();
      max_size.clear();
      start_pos.clear();
      end_pos.clear();
   }
}
Exemplo n.º 10
0
wstring TrimLeftW(const wstring& str)
{
	size_t n = str.find_first_not_of(L" \t\v");
	return (n == wstring::npos) ? str : str.substr(n, str.length());
}
Exemplo n.º 11
0
void TrimW(wstring& s)
{
	const wstring DropChar = L" ";
	s.erase(s.find_last_not_of(DropChar)+1);
	s.erase(0, s.find_first_not_of(DropChar));
}