コード例 #1
0
ファイル: parser.cpp プロジェクト: MrKuznetsov/hw-cpp
bool lvlPlusMinus(char *&c)
{
	delims(c); //пропускаем пробелы
	if (!lvlMulDiv(c)) //спускаемся на уровень вниз проверяя на первое слагаемое
		return false; //если ошибка 
	delims(c); //пропускаем пробелы
	while (*c == '+' || *c == '-') //проверяем на сложение и вычетание
	{
		c++; //смещаем позицию в строке
		if (!lvlMulDiv(c)) //спускаемся на уровень вниз тем самым прверяем на следующие слагаемые
			return false; //если ошибка
	}
	return true; //в случае успеха
}
コード例 #2
0
ファイル: parser.cpp プロジェクト: MrKuznetsov/hw-cpp
bool lvlMulDiv(char *&c)
{
	delims(c); //пропускаем пробелы
	if (!lvlBrackNum(c)) //спускаемся на уровень вниз проверяя на первый множитель
		return false;
	delims(c); //пропускаем пробелы
	while (*c == '*' || *c == '/')
	{
		c++; //смещаем позицию в строке
		if (!lvlBrackNum(c)) //спускаемся на уровень вниз тем самым прверяем на следующие множители
			return false;
	}
	return true; //успех
}
コード例 #3
0
void ExtImportPrefs::OnRuleTableEdit (wxGridEvent& event)
{
   int row = event.GetRow();
   int col = event.GetCol();
   ExtImportItems *items = wxGetApp().mImporter->GetImportItems();
   ExtImportItem *item = &(*items)[row];
   RuleTable->SaveEditControlValue();

   wxString val = RuleTable->GetCellValue (row, col);
   int fixSpaces = wxNO;
   bool askedAboutSpaces = false;
   wxArrayString vals;
   wxString delims(wxT(":"));
   wxGetApp().mImporter->StringToList (val, delims, vals);
   switch (col)
   {
   case 0:
      item->extensions.Clear();
      break;
   case 1:
      item->mime_types.Clear();
      break;
   }      
   
   for (size_t i = 0; i < vals.Count(); i++)
   {
      
      wxString trimmed = vals[i];
      trimmed.Trim().Trim(false);
      if (trimmed.Cmp(vals[i]) != 0)
      {
         if (!askedAboutSpaces)
         {
            fixSpaces = wxMessageBox(_(
"There are space characters (spaces, newlines, tabs or linefeeds) in one of \
the items. They are likely to break the pattern matching. Unless you know \
what you are doing, it is recommended to trim spaces. Do you want \
Audacity to trim spaces for you?"
            ),_("Spaces detected"), wxYES_NO);
            askedAboutSpaces = true;
         }
         if (fixSpaces != wxYES)
         {
            trimmed = vals[i];
         }
         else
         {
            vals[i] = trimmed;
         }
      }
      switch (col)
      {
      case 0:
         item->extensions.Add (trimmed);
         break;
      case 1:
         item->mime_types.Add (trimmed);
         break;
      }      
   }
コード例 #4
0
ファイル: SettingsManager.cpp プロジェクト: chhawk/MyGUI
	void SettingsManager::setValue(const std::string& _path, const std::string& _value)
	{
		pugi::xpath_node node = mUserDocument->document_element().select_single_node(_path.c_str());
		if (!node.node().empty())
		{
			node.node().text().set(_value.c_str());
		}
		else
		{
			std::vector<std::string> names;
			std::string delims("/");
			names = MyGUI::utility::split(_path, delims);

			pugi::xml_node currentNode = mUserDocument->document_element();
			for (std::vector<std::string>::const_iterator name = names.begin(); name != names.end(); name ++)
			{
				pugi::xml_node childNode = currentNode.child((*name).c_str());
				if (childNode.empty())
					childNode = currentNode.append_child((*name).c_str());

				currentNode = childNode;
			}

			currentNode.text().set(_value.c_str());
		}

		eventSettingsChanged(_path);
	}
コード例 #5
0
ファイル: parser.cpp プロジェクト: MrKuznetsov/hw-cpp
bool lvlBrackNum(char *&c)
{
	delims(c); //удаляем пробелы
	if (*c == '(') //если открывающая скоба
	{
		c++; //смещаем позицию
		if (!lvlPlusMinus(c)) //запускаем анализатор снчала
			return false; //ошибка
		if (delims(c)) //удаляем пробелы и проверяем на конец строки
			return false;
		if (*c != ')') //если нет закр. скобы - ошибка
			return false;
		c++; //смещаем позицию
		return true; //успех
	} else //if (isDig(*c))
		return isFloat(c);
	//else return false;

}
コード例 #6
0
ファイル: SettingsManager.cpp プロジェクト: chhawk/MyGUI
	void SettingsManager::setValueList(const std::string& _path, const VectorString& _values)
	{
		if (!MyGUI::utility::endWith(_path, ".List"))
			return;

		std::string itemName = "Value";

		pugi::xml_node targetNode;

		pugi::xpath_node node = mUserDocument->document_element().select_single_node(_path.c_str());
		if (!node.node().empty())
		{
			targetNode = node.node();
			while (!targetNode.first_child().empty())
				targetNode.remove_child(targetNode.first_child());
		}
		else
		{
			std::vector<std::string> names;
			std::string delims("/");
			names = MyGUI::utility::split(_path, delims);

			pugi::xml_node currentNode = mUserDocument->document_element();
			for (std::vector<std::string>::const_iterator name = names.begin(); name != names.end(); name ++)
			{
				pugi::xml_node childNode = currentNode.child((*name).c_str());
				if (childNode.empty())
					childNode = currentNode.append_child((*name).c_str());

				currentNode = childNode;
			}

			targetNode = currentNode;
		}

		for (VectorString::const_iterator value = _values.begin(); value != _values.end(); value ++)
			targetNode.append_child(itemName.c_str()).text().set((*value).c_str());

		eventSettingsChanged(_path);
	}
コード例 #7
0
ファイル: StringUtils.cpp プロジェクト: kablammyman/Utils
std::vector<std::string> StringUtils::Tokenize(std::string path, char delim)
{
	std::string delims(1, delim);
	return Tokenize(path, delims);
}
コード例 #8
0
void Importer::ReadImportItems()
{
   int item_counter = 0;
   wxStringTokenizer toker;
   wxString item_name;
   wxString item_value;
   ExtImportItem *new_item;
   ImportPluginList::compatibility_iterator importPluginNode;
   
   if (this->mExtImportItems != NULL)
      delete this->mExtImportItems;
      
   this->mExtImportItems = new ExtImportItems();
   /* Rule string format is:
    * extension1:extension2:extension3\mime_type1:mime_type2:mime_type3|filter1:filter2:filter3\unusedfilter1:unusedfilter2
    * backslashes are escaped and unescaped internally
    */
   for (item_counter = 0; true; item_counter++)
   {
      wxString condition, filters, used_filters, unused_filters = wxEmptyString, extensions, mime_types = wxEmptyString;
      item_name.Printf (wxT("/ExtImportItems/Item%d"), item_counter);
      /* Break at first non-existent item */
      if (!gPrefs->Read(item_name, &item_value))
        break;
        
      toker.SetString(item_value, wxT("|"), wxTOKEN_RET_EMPTY_ALL);
      /* Break at first broken item */
      if (toker.CountTokens() != 2)
        break;

      new_item = new ExtImportItem();
        
      /* First token is the filtering condition, second - the filter list */
      condition = toker.GetNextToken();
      filters = toker.GetNextToken();

      /* Condition token consists of extension list and mime type list
       * mime type list can be omitted entirely (complete with '\' separator)*/
      toker.SetString(condition, wxT("\\"), wxTOKEN_RET_EMPTY_ALL);
      extensions = toker.GetNextToken();
      if (toker.HasMoreTokens())
        mime_types = toker.GetNextToken();

      wxString delims(wxT(":"));
      StringToList (extensions, delims, new_item->extensions);

      if (mime_types != wxEmptyString)
         StringToList (mime_types, delims, new_item->mime_types);
      
      /* Filter token consists of used and unused filter lists */
      toker.SetString(filters, wxT("\\"), wxTOKEN_RET_EMPTY_ALL);
      used_filters = toker.GetNextToken();
      if (toker.HasMoreTokens())
        unused_filters = toker.GetNextToken();
      
      StringToList (used_filters, delims, new_item->filters);

      if (unused_filters != wxEmptyString)
      {
         /* Filters are stored in one list, but the position at which
          * unused filters start is remembered
          */
         new_item->divider = new_item->filters.Count();
         StringToList (unused_filters, delims, new_item->filters);
      }
      else
         new_item->divider = -1;
      
      /* Find corresponding filter object for each filter ID */
      for (size_t i = 0; i < new_item->filters.Count(); i++)
      {
         for (importPluginNode = mImportPluginList->GetFirst();
            importPluginNode; importPluginNode = importPluginNode->GetNext())
         {
            ImportPlugin *importPlugin = importPluginNode->GetData();
            if (importPlugin->GetPluginStringID().Cmp(new_item->filters[i]) == 0)
            {
               new_item->filter_objects.Add (importPlugin);
               break;
            }
         }
         /* IDs that do not have corresponding filters, will be shown as-is */
         if (!importPluginNode)
           new_item->filter_objects.Add (NULL);
      }
      /* Find all filter objects that are not present in the filter list */
      for (importPluginNode = mImportPluginList->GetFirst();
         importPluginNode; importPluginNode = importPluginNode->GetNext())
      {
         bool found = false;
         ImportPlugin *importPlugin = importPluginNode->GetData();
         for (size_t i = 0; i < new_item->filter_objects.Count(); i++)
         {
            if (importPlugin == new_item->filter_objects[i])
            {
               found = true;
               break;
            }
         }
         /* Add these filters at the bottom of used filter list */
         if (!found)
         {
            int index = new_item->divider;
            if (new_item->divider < 0)
               index = new_item->filters.Count();
            new_item->filters.Insert(importPlugin->GetPluginStringID(),index);
            new_item->filter_objects.Insert (importPlugin, index);
            if (new_item->divider >= 0)
               new_item->divider++;
         }
      }
      this->mExtImportItems->Add (new_item);
   }
}
コード例 #9
0
ファイル: tparse.cpp プロジェクト: codeaudit/BIDMach
int main(int argc, char ** argv) {
  int iline=0, i, iarg=1, nfields=1, jmax=0, writetxt=0, writemat=0, grpsize=1;
  int membuf=1048576;
  char * here, *linebuf, *readbuf;
  string ifname = "", ofname = "", mfname = "", ffname = "", matfname = "", fdelim="\t", suffix="";
  if (argc < 2) {
    printf("%s", usage);
    return 1;
  }
  while (iarg < argc) {
    if (strncmp(argv[iarg], "-d", 2) == 0) {
      fdelim = argv[++iarg];
    } else if (strncmp(argv[iarg], "-c", 2) == 0) {
      suffix=".gz";
    } else if (strncmp(argv[iarg], "-f", 2) == 0) {
      ffname = argv[++iarg];
    } else if (strncmp(argv[iarg], "-i", 2) == 0) {
      ifname = argv[++iarg];
    } else if (strncmp(argv[iarg], "-m", 2) == 0) {
      mfname = argv[++iarg];
    } else if (strncmp(argv[iarg], "-o", 2) == 0) {
      ofname = argv[++iarg];
    } else if (strncmp(argv[iarg], "-s", 2) == 0) {
      membuf = strtol(argv[++iarg],NULL,10);
    } else if (strncmp(argv[iarg], "-?", 2) == 0) {
      printf("%s", usage);
      return 1;
    } else if (strncmp(argv[iarg], "-h", 2) == 0) {
      printf("%s", usage);
      return 1;
    } else {
      cout << "Unknown option " << argv[iarg] << endl;
      exit(1);
    }
    iarg++;
  }
  if (mfname.size() == 0) mfname = ofname;
  ivector tvec(0);
  svector delims(0);
  svector dnames(0);
  nfields = parseFormat(ffname, tvec, dnames, delims, &grpsize);
  srivector srv(nfields);
  ftvector ftv(nfields);

  istream * ifstr;
  linebuf = new char[membuf];
  readbuf = new char[membuf];

  ifstr = open_in_buf(ifname, readbuf, membuf);

  while (!ifstr->bad() && !ifstr->eof()) {
    ifstr->getline(linebuf, membuf-1);
    linebuf[membuf-1] = 0;
    if (ifstr->fail()) {
      ifstr->clear();
      ifstr->ignore(LONG_MAX,'\n');
    }
    if (strlen(linebuf) > 0) {
      jmax++;
      try {
        parseLine(linebuf, membuf, ++iline, fdelim.c_str(), tvec, delims, srv, ftv, grpsize);
      } catch (int e) {
        cerr << "Continuing" << endl;
      }
    }
    if ((jmax % 100000) == 0) {
      cout<<"\r"<<jmax<<" lines processed";
      cout.flush();
    }
  }
  if (ifstr) delete ifstr;
  cout<<"\r"<<jmax<<" lines processed";
  cout.flush();

  for (i = 0; i < nfields; i++) {
    switch (tvec[i]) {
    case ftype_int: case ftype_dt: case ftype_mdt: case ftype_date: case ftype_mdate: case ftype_cmdate:
      ftv[i].writeInts(ofname + dnames[i] + ".imat" + suffix);
      break;
    case ftype_dint:
      ftv[i].writeDInts(ofname + dnames[i] + ".dimat" + suffix);
      break;
    case ftype_qhex:
      ftv[i].writeQInts(ofname + dnames[i] + ".imat" + suffix);
      break;
    case ftype_float:
      ftv[i].writeFloats(ofname + dnames[i] + ".fmat" + suffix);
      break;
    case ftype_double:
      ftv[i].writeDoubles(ofname + dnames[i] + ".dmat" + suffix);
      break;
    case ftype_word:
      ftv[i].writeInts(ofname + dnames[i] + ".imat" + suffix);
      srv[i].writeMap(mfname + dnames[i], suffix);
      break;
    case ftype_string: case ftype_group: 
      ftv[i].writeIVecs(ofname + dnames[i] + ".imat" + suffix);
      srv[i].writeMap(mfname + dnames[i], suffix);
      break;
    case ftype_igroup:
      ftv[i].writeIVecs(ofname + dnames[i] + ".imat" + suffix);
      break;
    case ftype_digroup:
      ftv[i].writeDIVecs(ofname + dnames[i]);
      break;
    default:
      break;
    }    
  }
  printf("\n");
  if (linebuf) delete [] linebuf;
  return 0;
}
コード例 #10
0
ファイル: parser.cpp プロジェクト: MrKuznetsov/hw-cpp
bool parse(char *c)
{
	char *tmp = c;
	return lvlPlusMinus(tmp) && delims(tmp);
}
コード例 #11
0
bool 
hoxChesscapePlayer::_ParseTablePlayersString( 
								const wxString&      playersInfoStr,
	                            hoxNetworkTableInfo& tableInfo ) const
{
	wxString delims( (wxChar) 0x20 );
	wxStringTokenizer tkz( playersInfoStr, delims, wxTOKEN_RET_EMPTY );
	
	wxString token;
	int      position = 0;
	long     score;

	while ( tkz.HasMoreTokens() )
	{
		token = tkz.GetNextToken();
		switch ( position )
		{
			case 0:	
				tableInfo.redId = token; 
				if ( tableInfo.redId.empty() )
				{
					tableInfo.redScore = "0";
					position = 1;  // Skip RED 's Score.
				}
				break;

			case 1:
				if ( !token.empty() && ! token.ToLong( &score ) ) // not a number?
				{
					// The current token must be a part of the player's Id.
					tableInfo.redId += " " + token;
					--position;
					break;
				}
				tableInfo.redScore   = token; 
				break;

			case 2:
				if (   token.empty()
					&& !tableInfo.redId.empty() && tableInfo.redScore.empty() ) // RED is guest?
				{
					// Skip this empty token since it is a part of the RED Guest info.
					--position;
					break;
				}
				tableInfo.blackId = token; 
				break;

			case 3:	
				if ( !token.empty() && ! token.ToLong( &score ) ) // not a number?
				{
					// The current token must be a part of the player's Id.
					tableInfo.blackId += " " + token;
					--position;
					break;
				}
				tableInfo.blackScore = token; 
				break;

			default:
				break;
		}
		++position;
	}

	return true;
}