Example #1
0
void loadExpectations(Dictionary &headerCoverage, Dictionary &testMetrics, StringList &testOrder) {
	const char * const	processor= isIntel() ? "i386" : "ppc";
	io::File			expectations(std::string("tests/test_")+processor+".txt",
										io::File::Text, io::File::ReadOnly);
	std::string			line;
	Dictionary			*current= NULL;
	bool				eof;

	do	{
		expectations.readline(line);
		eof= (line.size() == 0);
		if(strip(line).size() == 0) {
			// ignore blank lines
		} else if(line[0] == '-') {
			if(line == "-header") {
				current= &headerCoverage;
			} else if(line == "-test") {
				current= &testMetrics;
			} else {
				current= NULL;
			}
		} else if(NULL != current) {
			StringList	parts;
			String		key, value;
			String		separator= "";

			for(std::string::size_type c= 0; c < line.size(); ++c) {
				if(line[c] == ' ') {
					line[c]= '\t';
				}
			}
			split(line, '\t', parts);
			key= parts[0];
			if(current == &testMetrics) {
				testOrder.push_back(key);
			}
			parts.erase(parts.begin());
			while(parts.size() > 0) {
				if(parts[0].size() > 0) {
					value+= separator + parts[0];
					separator= ';';
				}
				parts.erase(parts.begin());
			}
			(*current)[key]= value;
		}
	} while(!eof);
}
  String ConsoleUtils::breakString_(const OpenMS::String& input, const Size indentation, const Size max_lines)
  {

    // get the line length
    const Int line_len = ConsoleUtils::readConsoleSize_();

    StringList result;
    Size short_line_len = line_len - indentation;
    if (short_line_len < 1)
    {
      std::cerr << "INTERNAL ERROR: cannot split lines into empty strings! see breakString_()";
      return input;
    }
    for (Size i = 0; i < input.size(); )
    {
      String line = input.substr(i, result.size() == 0 ? line_len : short_line_len); // first line has full length
      Size advance_size = line.size();
      if (line.hasSubstring("\n"))
      {
        advance_size = 0;
        while (line.hasPrefix("\n"))
        {
          line = line.substr(1);
          ++advance_size;
        } // advance by # of \n's
        if (line.hasSubstring("\n")) line = line.prefix('\n');
        advance_size += line.size(); // + actual chars
      }

      // check if we are using the full length and split a word at the same time
      // cut a little earlier in that case for nicer looks
      if (line.size() ==  (result.size() == 0 ? line_len : short_line_len) && short_line_len > 8 && line.rfind(' ') != String::npos)
      {
        String last_word = line.suffix(' ');
        if (last_word.length() < 4)
        { // shorten by last word (will move to the next line)
          line = line.prefix(line.size() - last_word.length());
          advance_size -= last_word.size(); // + actual chars
        }
      }

      i += advance_size;
      String s_intend = (result.size() == 0 ? "" : String(indentation, ' ')); // first line no indentation
      String r = s_intend + (result.size() == 0 ? line : line.trim()); // intended lines get trimmed
      result.push_back(r); //(r.fillRight(' ', (UInt) line_len));
    }
    if (result.size() > max_lines) // remove lines from end if we get too many (but leave the last one)...
    {
      String last = result.back();
      result.erase(result.begin() + max_lines - 2, result.end());
      result.push_back((String(indentation, ' ') + String("..."))); //.fillRight(' ',(UInt) line_len));
      result.push_back(last);
    }
    // remove last " " from last line to prevent automatic linebreak
    //if (result.size()>0 && result[result.size()-1].hasSuffix(" ")) result[result.size()-1] = result[result.size()-1].substr(0,result[result.size()-1].size()-1);
    return ListUtils::concatenate(result, "\n");
  }
Example #3
0
StringList UserTextIdentificationFrame::fieldList() const
{
  StringList l = TextIdentificationFrame::fieldList();

  if(!l.isEmpty()) {
    StringList::Iterator it = l.begin();
    l.erase(it);
  }

  return l;
}
Example #4
0
void TestRootBoard::cmpMates(std::string bstr, std::string mstr) {
    Move ml[256];
    Move* good = ml+192;
    Move* bad=good;
    b->setup(bstr);
    b->boards[0].wb.generateMateMoves<false, void>(&good, &bad);
    StringList mstrl = split(mstr);
    while(good < ml+192) {
        std::string res = good++->algebraic();
        StringList::iterator i = find(mstrl.begin(), mstrl.end(), res);
        if (i!=mstrl.end())
            mstrl.erase(i);
        else
            std::cerr << bstr << ": " << res << " missing mate" << std::endl; }
    for (StringList::iterator i = mstrl.begin(); i != mstrl.end(); ++i) {
        std::cerr << bstr << ": " << *i << " wrong mate" << std::endl; } }
Example #5
0
StringList UserProfileHandler::getUserProfileNames(bool onlyRealDir) {
	StringList result;

	Config & config = ConfigManager::getInstance().getCurrentConfig();
	File path(File::convertPathSeparators(config.getConfigDir() + "profiles/"));
	result = path.getDirectoryList();

	if (onlyRealDir) {
		StringList::iterator begin = result.begin();
		for (int interator = result.size(); --interator >= 0; ) {
			if (String(result[interator]).endsWith(".new") || String(result[interator]).endsWith(".old")) {
				result.erase(begin + interator);
			}
		}
	}

	return result;
}
Example #6
0
/** 
Function to delete an entry from Hash

@internalComponent
@released

@param aString - String which needs to be deleted
*/
void HashTable::Delete(String aString)
{
	unsigned int hashVal = Hash(aString);
	if(iTable[hashVal].size() > 0)
	{
		StringList list = iTable[hashVal];
		StringList::iterator beginIter = list.begin();
		StringList::iterator endIter = list.end();
		while(beginIter != endIter)
		{
			if((*beginIter) == aString)
			{
				list.erase(beginIter);
				iTable[hashVal] = list;
				return;
			}
			++beginIter;
		}
	}
}
Example #7
0
int main ()
{
    // Create a list of critters.
    StringList critters;

    // Insert a few critters.
    critters.insert (critters.begin (), "antelope");
    critters.insert (critters.begin (), "bear");
    critters.insert (critters.begin (), "cat");

    // Print out the list.
    std::cout << critters << '\n';

    // Change cat to cougar.
    *std::find (critters.begin (),critters.end (), "cat") = "cougar";
    std::cout << critters << '\n';

    // Put a zebra at the beginning, an ocelot ahead of antelope,
    // and a rat at the end.
    critters.push_front ("zebra");
    critters.insert (std::find (critters.begin (), critters.end (),
                                "antelope"), "ocelot");
    critters.push_back ("rat");
    std::cout << critters << '\n';

    // Sort the list (Use list's sort function since the 
    // generic algorithm requires a random access iterator 
    // and list only provides bidirectional)
    critters.sort ();
    std::cout << critters << '\n';

    // Now let's erase half of the critters.
    StringList::size_type half = critters.size () / 2;
    for (StringList::size_type i = 0; i != half; ++i)
        critters.erase (critters.begin ());

    std::cout << critters << '\n';
  
    return 0;
}
Example #8
0
int
main(int argc, char **argv)
{
	StringList stringList;
	StringList::iterator pos;

	stringList.push_back(&a);
	stringList.push_back(&b);
	pos = stringList.begin();
	stringList.insert(pos, &c);

	for (pos = stringList.begin(); pos != stringList.end(); ++pos) {
		cout << *pos << endl;
		string *s = *pos;
		cout << s->c_str() << (*pos)->c_str() << endl;
	}

	for (pos = stringList.begin(); pos != stringList.end(); ) {
		cout << *pos << endl;
		pos = stringList.erase(pos);
	}
}
Example #9
0
bool CTagLoaderTagLib::ParseTag(ID3v2::Tag *id3v2, MUSIC_INFO::EmbeddedArt *art, MUSIC_INFO::CMusicInfoTag& tag)
{
  if (!id3v2) return false;
  ReplayGain replayGainInfo;

  ID3v2::AttachedPictureFrame *pictures[3] = {};
  const ID3v2::FrameListMap& frameListMap = id3v2->frameListMap();
  for (ID3v2::FrameListMap::ConstIterator it = frameListMap.begin(); it != frameListMap.end(); ++it)
  {
    // It is possible that the taglist is empty. In that case no useable values can be extracted.
    // and we should skip the tag.
    if (it->second.isEmpty()) continue;

    if      (it->first == "TPE1")   SetArtist(tag, GetID3v2StringList(it->second));
    else if (it->first == "TALB")   tag.SetAlbum(it->second.front()->toString().to8Bit(true));
    else if (it->first == "TPE2")   SetAlbumArtist(tag, GetID3v2StringList(it->second));
    else if (it->first == "TIT2")   tag.SetTitle(it->second.front()->toString().to8Bit(true));
    else if (it->first == "TCON")   SetGenre(tag, GetID3v2StringList(it->second));
    else if (it->first == "TRCK")   tag.SetTrackNumber(strtol(it->second.front()->toString().toCString(true), NULL, 10));
    else if (it->first == "TPOS")   tag.SetDiscNumber(strtol(it->second.front()->toString().toCString(true), NULL, 10));
    else if (it->first == "TYER")   tag.SetYear(strtol(it->second.front()->toString().toCString(true), NULL, 10));
    else if (it->first == "TCMP")   tag.SetCompilation((strtol(it->second.front()->toString().toCString(true), NULL, 10) == 0) ? false : true);
    else if (it->first == "TENC")   {} // EncodedBy
    else if (it->first == "TCOP")   {} // Copyright message
    else if (it->first == "TDRC")   tag.SetYear(strtol(it->second.front()->toString().toCString(true), NULL, 10));
    else if (it->first == "TDRL")   tag.SetYear(strtol(it->second.front()->toString().toCString(true), NULL, 10));
    else if (it->first == "TDTG")   {} // Tagging time
    else if (it->first == "TLAN")   {} // Languages
    else if (it->first == "TMOO")   tag.SetMood(it->second.front()->toString().to8Bit(true));
    else if (it->first == "USLT")
      // Loop through any lyrics frames. Could there be multiple frames, how to choose?
      for (ID3v2::FrameList::ConstIterator lt = it->second.begin(); lt != it->second.end(); ++lt)
      {
        ID3v2::UnsynchronizedLyricsFrame *lyricsFrame = dynamic_cast<ID3v2::UnsynchronizedLyricsFrame *> (*lt);
        if (lyricsFrame)
          tag.SetLyrics(lyricsFrame->text().to8Bit(true));
      }
    else if (it->first == "COMM")
      // Loop through and look for the main (no description) comment
      for (ID3v2::FrameList::ConstIterator ct = it->second.begin(); ct != it->second.end(); ++ct)
      {
        ID3v2::CommentsFrame *commentsFrame = dynamic_cast<ID3v2::CommentsFrame *> (*ct);
        if (commentsFrame && commentsFrame->description().isEmpty())
          tag.SetComment(commentsFrame->text().to8Bit(true));
      }
    else if (it->first == "TXXX")
      // Loop through and process the UserTextIdentificationFrames
      for (ID3v2::FrameList::ConstIterator ut = it->second.begin(); ut != it->second.end(); ++ut)
      {
        ID3v2::UserTextIdentificationFrame *frame = dynamic_cast<ID3v2::UserTextIdentificationFrame *> (*ut);
        if (!frame) continue;

        // First field is the same as the description
        StringList stringList = frame->fieldList();
        if (stringList.size() == 1) continue;
        stringList.erase(stringList.begin());
        String desc = frame->description().upper();
        if      (desc == "MUSICBRAINZ ARTIST ID")
          tag.SetMusicBrainzArtistID(SplitMBID(StringListToVectorString(stringList)));
        else if (desc == "MUSICBRAINZ ALBUM ID")
          tag.SetMusicBrainzAlbumID(stringList.front().to8Bit(true));
        else if (desc == "MUSICBRAINZ ALBUM ARTIST ID")
          tag.SetMusicBrainzAlbumArtistID(SplitMBID(StringListToVectorString(stringList)));
        else if (desc == "MUSICBRAINZ ALBUM ARTIST")
          SetAlbumArtist(tag, StringListToVectorString(stringList));
        else if (desc == "REPLAYGAIN_TRACK_GAIN")
          replayGainInfo.ParseGain(ReplayGain::TRACK, stringList.front().toCString(true));
        else if (desc == "REPLAYGAIN_ALBUM_GAIN")
          replayGainInfo.ParseGain(ReplayGain::ALBUM, stringList.front().toCString(true));
        else if (desc == "REPLAYGAIN_TRACK_PEAK")
          replayGainInfo.ParsePeak(ReplayGain::TRACK, stringList.front().toCString(true));
        else if (desc == "REPLAYGAIN_ALBUM_PEAK")
          replayGainInfo.ParsePeak(ReplayGain::ALBUM, stringList.front().toCString(true));
        else if (desc == "ALBUMARTIST" || desc == "ALBUM ARTIST")
          SetAlbumArtist(tag, StringListToVectorString(stringList));
        else if (desc == "ARTISTS")
        {
          if (id3v2->header()->majorVersion() < 4)
            tag.SetMusicBrainzArtistHints(StringListToVectorString(TagLib::StringList::split(stringList.front(), TagLib::String("/"))));
          else
            tag.SetMusicBrainzArtistHints(StringListToVectorString(stringList));
        }
        else if (desc == "ALBUMARTISTS" || desc == "ALBUM ARTISTS")
        {
          if (id3v2->header()->majorVersion() < 4)
            tag.SetMusicBrainzAlbumArtistHints(StringListToVectorString(TagLib::StringList::split(stringList.front(), TagLib::String("/"))));
          else
            tag.SetMusicBrainzAlbumArtistHints(StringListToVectorString(stringList));
        }
        else if (desc == "MOOD")
          tag.SetMood(stringList.front().to8Bit(true));
        else if (g_advancedSettings.m_logLevel == LOG_LEVEL_MAX)
          CLog::Log(LOGDEBUG, "unrecognized user text tag detected: TXXX:%s", frame->description().toCString(true));
      }
    else if (it->first == "UFID")
      // Loop through any UFID frames and set them
      for (ID3v2::FrameList::ConstIterator ut = it->second.begin(); ut != it->second.end(); ++ut)
      {
        ID3v2::UniqueFileIdentifierFrame *ufid = reinterpret_cast<ID3v2::UniqueFileIdentifierFrame*> (*ut);
        if (ufid->owner() == "http://musicbrainz.org")
        {
          // MusicBrainz pads with a \0, but the spec requires binary, be cautious
          char cUfid[64];
          int max_size = std::min((int)ufid->identifier().size(), 63);
          strncpy(cUfid, ufid->identifier().data(), max_size);
          cUfid[max_size] = '\0';
          tag.SetMusicBrainzTrackID(cUfid);
        }
      }
    else if (it->first == "APIC")
      // Loop through all pictures and store the frame pointers for the picture types we want
      for (ID3v2::FrameList::ConstIterator pi = it->second.begin(); pi != it->second.end(); ++pi)
      {
        ID3v2::AttachedPictureFrame *pictureFrame = dynamic_cast<ID3v2::AttachedPictureFrame *> (*pi);
        if (!pictureFrame) continue;

        if      (pictureFrame->type() == ID3v2::AttachedPictureFrame::FrontCover) pictures[0] = pictureFrame;
        else if (pictureFrame->type() == ID3v2::AttachedPictureFrame::Other)      pictures[1] = pictureFrame;
        else if (pi == it->second.begin())                                        pictures[2] = pictureFrame;
      }
    else if (it->first == "POPM")
      // Loop through and process ratings
      for (ID3v2::FrameList::ConstIterator ct = it->second.begin(); ct != it->second.end(); ++ct)
      {
        ID3v2::PopularimeterFrame *popFrame = dynamic_cast<ID3v2::PopularimeterFrame *> (*ct);
        if (!popFrame) continue;

        // @xbmc.org ratings trump others (of course)
        if      (popFrame->email() == "*****@*****.**")
          tag.SetUserrating(popFrame->rating() / 51 + '0');
        else if (tag.GetUserrating() == '0')
        {
          if (popFrame->email() != "Windows Media Player 9 Series" &&
              popFrame->email() != "Banshee" &&
              popFrame->email() != "no@email" &&
              popFrame->email() != "*****@*****.**" &&
              popFrame->email() != "*****@*****.**")
            CLog::Log(LOGDEBUG, "unrecognized ratings schema detected: %s", popFrame->email().toCString(true));
          tag.SetUserrating(POPMtoXBMC(popFrame->rating()));
        }
      }
    else if (g_advancedSettings.m_logLevel == LOG_LEVEL_MAX)
      CLog::Log(LOGDEBUG, "unrecognized ID3 frame detected: %c%c%c%c", it->first[0], it->first[1], it->first[2], it->first[3]);
  } // for

  // Process the extracted picture frames; 0 = CoverArt, 1 = Other, 2 = First Found picture
  for (int i = 0; i < 3; ++i)
    if (pictures[i])
    {
      std::string  mime =            pictures[i]->mimeType().to8Bit(true);
      TagLib::uint size =            pictures[i]->picture().size();
      tag.SetCoverArtInfo(size, mime);
      if (art)
        art->set((const uint8_t*)pictures[i]->picture().data(), size, mime);

      // Stop after we find the first picture for now.
      break;
    }

  tag.SetReplayGain(replayGainInfo);
  return true;
}
Example #10
0
int __cdecl main(int argc, char* argv[])
{
	if(argc < 3) {
		return 0;
	}
	
	try {
		string tmp;
		File src(argv[1], File::READ, File::OPEN, false);
		File tgt(argv[2], File::WRITE, File::CREATE | File::TRUNCATE, false);
		File example(argv[3], File::WRITE, File::CREATE | File::TRUNCATE, false);
		string x = src.read();
		x = Text::acpToUtf8(x);
		string::size_type k;
		
		while((k = x.find('\r')) != string::npos) {
			x.erase(k, 1);
		}

		StringList l = StringTokenizer<string>(x, '\n').getTokens();

		StringIter i;
		string varStr;
		string varName;
		string start;

		SimpleXML ex;

		for(i = l.begin(); i != l.end(); ) {
			if( (k = i->find("// @Strings: ")) != string::npos) {
				varStr = i->substr(k + 13);
				i = l.erase(i);
			} else if( (k = i->find("// @Names: ")) != string::npos) {
				varName = i->substr(k + 11);
				i = l.erase(i);
			} else if(i->find("// @DontAdd") != string::npos) {
				i = l.erase(i);
			} else if( (k = i->find("// @Prolog: ")) != string::npos) {
				start += i->substr(k + 12) + "\r\n";
				i = l.erase(i);
			} else if(i->size() < 5) {
				i = l.erase(i);
			} else {
				++i;
			}
		}

		if(varStr.empty() || varName.empty()) {
			printf("No @Strings or @Names\n");
			return 0;
		}
		
		varStr += " = {\r\n";
		varName += " = {\r\n";
/*		
		ex.addTag("Language");
		ex.addChildAttrib("Name", string("Example Language"));
		ex.addChildAttrib("Author", string("FlylinkDC++ Development Team"));
		//ex.addChildAttrib("Version", string(A_VERSIONSTRING));
		ex.addChildAttrib("Revision", string("1"));
		ex.stepIn();
*/
		ex.addTag("resources");
		ex.stepIn();
		string name;
		string def;
		string xmldef;
		string s;
		for(i = l.begin(); i != l.end(); i++) {

			name.clear();
			s = *i;

			bool u = true;
			for(k = s.find_first_not_of(" \t"); s[k] != ','; k++) {
				if(s[k] == '_') {
					u = true;
				} else if(u) {
					name+=s[k];
					u = false;
				} else {
					name+=(char)tolower(s[k]);
				}
			}

			k = s.find("// ");
			def = s.substr(k + 3);
			xmldef = def.substr(1, def.size() - 2);
/*			while( (k = xmldef.find("\\t")) != string::npos) {
				xmldef.replace(k, 2, "\t");
			}
			while( (k = xmldef.find("\\r")) != string::npos) {
				xmldef.replace(k, 2, "\r");
			}
			while( (k = xmldef.find("\\n")) != string::npos) {
				xmldef.replace(k, 2, "\n");
			}

			while( (k = xmldef.find("\\\\")) != string::npos) {
				xmldef.replace(k, 2, "\\");
			}
			*/
			ex.addTag("string", xmldef);
			ex.addChildAttrib("name", name);

			varStr += def + ", \r\n";
			varName += '\"' + name + "\", \r\n";

		}

		varStr.erase(varStr.size()-2, 2);
		varName.erase(varName.size()-2, 2);

		varStr += "\r\n};\r\n";
		varName += "\r\n};\r\n";

		tgt.write(start);
		tgt.write(varStr);
		tgt.write(varName);

		example.write(SimpleXML::utf8Header);
		example.write(ex.toXML());
	} catch(const Exception& e) {
		printf("%s\n", e.getError().c_str());
	}

	return 0;
}
Example #11
0
void
Slice::ObjCGenerator::MetaDataVisitor::validate(const ContainedPtr& cont)
{
    ModulePtr m = ModulePtr::dynamicCast(cont);
    if(m)
    {
        bool error = false;
        bool foundPrefix = false;

        StringList meta = getMetaData(m);
        for(StringList::iterator p = meta.begin(); p != meta.end();)
        {
            string s = *p++;
            const string prefix = "objc:prefix:";
            string name;
            if(s.find(prefix) == 0)
            {
                foundPrefix = true;
                name = trim(s.substr(prefix.size()));
                if(name.empty())
                {
                    m->definitionContext()->warning(InvalidMetaData, m->definitionContext()->filename(),
                                                    m->line(), _msg + " `" + s + "'");
                    meta.remove(s);
                    error = true;
                }
                else
                {
                    if(!addModule(m, name))
                    {
                        modulePrefixError(m, s);
                    }
                }
            }
            else
            {
                m->definitionContext()->warning(InvalidMetaData, m->definitionContext()->filename(),
                                                m->line(), _msg + " `" + s + "'");
                meta.remove(s);
                error = true;
            }
        }
        setMetaData(m, meta);

        if(!error && !foundPrefix)
        {
            StringList names = splitScopedName(m->scoped());
            string name;
            for(StringList::const_iterator i = names.begin(); i != names.end(); ++i)
            {
                name += *i;
            }
            if(!addModule(m, name))
            {
                modulePrefixError(m, "");
            }
        }
    }

    EnumPtr en = EnumPtr::dynamicCast(cont);
    if(en)
    {
        StringList meta = getMetaData(en);
        for(StringList::iterator p = meta.begin(); p != meta.end();)
        {
            string s = *p;
            if(s != "objc:scoped")
            {
                en->definitionContext()->warning(InvalidMetaData, en->definitionContext()->filename(),
                                                en->line(), _msg + " `" + s + "'");
                meta.erase(p++);
            }
            else
            {
                ++p;
            }
        }
        setMetaData(en, meta);
    }
}