Example #1
0
void Parser::getMetaData(const std::string &data, MetaData &metadatas)
{
    const char comma = ',';
    auto find_str = std::find(data.cbegin(), data.cend(), comma );
    if ( find_str == data.cend() ) {
        return;
    } else {
        auto container = splitStringBy( data, comma );
        for( const auto &i: container ){
            if( i.find( "input" ) != std::string::npos ) {
                metadatas.input = getValue( i );
            } else if ( i.find( "lang" ) != std::string::npos ) {
                metadatas.lang = Tokens::getLanguage( getValue( i ) );
            } else if ( i.find( "run" ) != std::string::npos ) {
                metadatas.run_code = ( getValue( i ) == std::string { "true" } ? true :
                                getValue( i ) == std::string { "1" } ? true : false );
            } else if ( i.find( "private" ) != std::string::npos ) {
                metadatas.privacy = ( getValue( i ) == std::string { "true" } ? true :
                                getValue( i ) == std::string { "1" } ? true : false );
            }
        }
    }
    printf("MetaData: input => %s -- n_code => %s -- lang = %d -- run_code => %d -- privacy => %d\n",
            metadatas.input.c_str(), metadatas.n_code.c_str(), (int)metadatas.lang, (int)metadatas.run_code,
            metadatas.privacy );
}
Example #2
0
inline void Parser::getCodeTagAttributes( const std::string &text, std::string &data )
{
    auto find_iter = std::find( text.cbegin(), text.cend(), ']' );
    if( find_iter != text.cend() && find_iter != text.crend().base() ) {
        data = std::string( text.cbegin(), find_iter + 1 );
    }
}
Example #3
0
std::vector<std::string> Tokenize(const std::string& source, const std::string& delimiters, bool removeDelim /*= true*/)
{
	auto head = source.cbegin();
	std::vector<std::string> tokens;
	for (auto tail = source.cbegin(); tail != source.cend(); ++tail)
	{
		for (auto it = delimiters.cbegin(); it != delimiters.cend(); ++it)
		{
			const auto& delimiter = *it;

			if ((*tail == delimiter))
			{
				if (head != tail)
					tokens.push_back(std::string(head, tail));

				if (removeDelim)
					head = tail + 1;
				else
					head = tail;
			}
		}
	}

	if (head != source.cend())
		tokens.push_back(std::string(head, source.cend()));
	return tokens;
}
Example #4
0
	void run(const size_t messageCount){
		const size_t stringSize = 25;
		assert(stringSize <= TestClient::bufferSize);

		for(size_t i = 0; i < messageCount; ++i){
			const std::string currentString = TestClient::randomString(stringSize);
			std::copy(currentString.cbegin(), currentString.cend(), this->buffer.get());

			const ssize_t sendRes = send(this->serverSocketDescriptor, this->buffer.get(), stringSize, 0);
			if(sendRes == -1){
				throw std::runtime_error(std::string("send error: ") + strerror(errno));
			}

			std::cout << "Sent string:     '" << currentString << "'" << std::endl;

			const ssize_t recvRes = recv(this->serverSocketDescriptor, this->buffer.get(), TestClient::bufferSize, 0);
			if(recvRes == -1){
				throw std::runtime_error(std::string("recv error: ") + strerror(errno));
			}

			std::cout << "Recieved string: '";
			for(ssize_t pos = 0; pos < recvRes; ++pos){
				std::cout << this->buffer[pos];
			}

			std::cout << "'" << std::endl;

			const bool isEqual = std::equal(currentString.cbegin(), currentString.cend(), this->buffer.get());
			if(isEqual == false){
				throw std::runtime_error("reply is not equal");
			}

		}
	}
	/**! ctor from a line **/
	Sam (const std::string& line)
	{
		std::string::const_iterator iter1 {line.cbegin ()}, iter2 {line.cbegin ()};
		while (*++iter2 != '\t');
		QNAME = std::string {iter1, iter2};
		iter1 = ++iter2;

		while (*++iter2 != '\t');
		FLAG = std::bitset<SAM_FLAG::FLAG_SIZE> {std::stoul (std::string {iter1, iter2})};
		iter1 = ++iter2;

		while (*++iter2 != '\t');
		RNAME = std::string {iter1, iter2};
		iter1 = ++iter2;

		while (*++iter2 != '\t');
		POS = std::stoul (std::string {iter1, iter2});
		iter1 = ++iter2;

		while (*++iter2 != '\t');
		MAPQ = std::stoi (std::string {iter1, iter2});
		iter1 = ++iter2;

		while (*++iter2 != '\t');
		CIGAR = std::string {iter1, iter2};
		iter1 = ++iter2;

		while (*++iter2 != '\t');
		RNEXT = std::string {iter1, iter2};
		iter1 = ++iter2;

		while (*++iter2 != '\t');
		PNEXT = std::stoul (std::string {iter1, iter2});
		iter1 = ++iter2;

		while (*++iter2 != '\t');
		TLEN = std::stol (std::string {iter1, iter2});
		iter1 = ++iter2;

		while (*++iter2 != '\t');
		SEQ = std::string {iter1, iter2};
		iter1 = ++iter2;

		while (*++iter2 != '\t');
		QUAL = std::string {iter1, iter2};
		std::string Tag, Value;
		while (iter2 != line.cend ())
		{
			iter1 = ++iter2;
			iter2 += 2;
			Tag = std::string {iter1, iter2};
			iter1 += 5;
			while ( (*iter2 != '\t') && (iter2 != line.cend()))
				++iter2;
			Value = std::string {iter1, iter2};
			OPTIONAL_FIELDS.insert (std::make_pair (Tag, Value));
		}
	}
void OCLProgramBuilder::Add(const std::string& programString)
{
    if (find(programString.cbegin(), programString.cend(), '$') != programString.cend())
    {
        auto prg = CreateNumberedVersions(programString);
        programBuilder << prg;
    }
    else
    {
        programBuilder << programString;
    }	
}
Example #7
0
void OCLProgramUnit::AddCode(const std::string code)
{
    if (find(code.cbegin(), code.cend(), '$') != code.cend())
    {
        auto prg = CreateNumberedVersions(code);
        codeBuilder << endl << prg << endl;
    }
    else
    {
        codeBuilder << endl << code << endl;
    }
}
void ocl_program_unit::add_code(const std::string code)
{
    if (find(code.cbegin(), code.cend(), '$') != code.cend())
    {
        auto prg = create_numbered_versions(code);
        codeBuilder << endl << prg << endl;
    }
    else
    {
        codeBuilder << endl << code << endl;
    }
}
Example #9
0
    void decodeList(const std::string& encodedString, std::vector<sf::String>& list)
    {
        std::string item;

        for (auto it = encodedString.cbegin(); it != encodedString.cend(); ++it)
        {
            // Check if the character is an escape character
            if (*it == '\\')
            {
                auto next = it + 1;

                if (next == encodedString.cend())
                {
                    TGUI_OUTPUT("TGUI warning: Escape character at the end of the string. Ignoring character.");
                    continue;
                }
                else if ((*next == '\\') || (*next == '\"') || (*next == ','))
                {
                    item += *next;
                    ++it;
                }
                else if (*next == 'n')
                {
                    item += '\n';
                    ++it;
                }
                else if (*next == 't')
                {
                    item += '\t';
                    ++it;
                }
                else
                {
                    TGUI_OUTPUT(std::string("TGUI warning: Escape character in front of '") + *next + "'. Ignoring escape character.");
                    continue;
                }
            }
            else // No escape character
            {
                // Check if the next item starts here
                if (*it == ',')
                {
                    list.push_back(item);
                    item = "";
                }
                else // Just a normal character to be added to the string
                    item += *it;
            }
        }

        if (!item.empty())
            list.push_back(item);
    }
Example #10
0
bool Board::isCodeValid(const std::string &code)
{
    //check length
    if (code.length() != m_codeLength)
        return false;

    //check for invalid color code
    auto it = std::find_if(code.cbegin(), code.cend(),
                           [this](char c) {
        return (m_pegsColor.find(tolower(c)) == std::string::npos);
    });

    return it == code.cend();
}
Example #11
0
  boost::optional<std::string> matchre(std::string pattern)
  {
    boost::optional<std::string> maybe_token;

    /* FIXME: Not thread-safe.  */
    static std::unordered_map<std::string, std::regex *>_lookup;
    std::regex *rep;
    if (_lookup.count(pattern) == 0)
      {
	rep = new std::regex(pattern);
	_lookup[pattern] = rep;
      }
    else
      rep = _lookup[pattern];
    std::regex& re = *rep;

    /* Multiline is the default.  */
    std::regex_constants::match_flag_type flags = std::regex_constants::match_continuous;
    if (_pos > 0)
      flags |= std::regex_constants::match_prev_avail;
#ifdef BOOST_REGEX
    flags |= std::regex_constants::match_not_dot_newline;
#endif

    std::smatch match;
    int cnt = std::regex_search(_text.cbegin() + _pos, _text.cend(), match, re, flags);
    if (cnt > 0)
      {
	maybe_token = match[0];
	_pos += match[0].length();
      }

    return maybe_token;
  }
int main(int argc, char* argv[])
{
    // コマンドラインパース
    auto const command_line = process_command_line(argc, argv);

    // グラフファイルを開いてgraph_dataに導入
    std::ifstream ifs_graph(command_line.network);
    std::string const graph_data{std::istreambuf_iterator<char>(ifs_graph), std::istreambuf_iterator<char>()};
    ifs_graph.close();
    std::cout << "Loaded Graph: Length = " << graph_data.size() << std::endl;

    // graph_dataよりグラフパース
	bn::graph_t graph;
    bn::database_t data;
    std::tie(graph, data) = bn::serializer::bif().parse(graph_data.cbegin(), graph_data.cend());
    std::cout << "Parsed Graph: Num of Node = " << graph.vertex_list().size() << std::endl;

    // リンクファイルがあるなら,そのリンク状態にする
    if(command_line.link_info)
    {
        // 全てのリンクを削除
        graph.erase_all_edge();

        // リンクファイル読み込み
        std::ifstream ifs(command_line.link_info.get());
        bn::serializer::csv().load(ifs, graph);
        ifs.close();
    }

    // 書出
    std::ofstream ofs(command_line.output);
    bn::serializer::dot().write(ofs, graph, data);
    ofs.close();
}
Example #13
0
bool check_contains_non_digit(std::string w)
{
  for(auto i=w.cbegin();i != w.cend();++i)
    if(!isdigit(*i))
      return true;
  return false;
}
Example #14
0
static std::optional<PartitionType> ParsePartitionDirectoryName(const std::string& name)
{
  if (name.size() < 2)
    return {};

  if (!strcasecmp(name.c_str(), "DATA"))
    return PartitionType::Game;
  if (!strcasecmp(name.c_str(), "UPDATE"))
    return PartitionType::Update;
  if (!strcasecmp(name.c_str(), "CHANNEL"))
    return PartitionType::Channel;

  if (name[0] == 'P' || name[0] == 'p')
  {
    // e.g. "P-HA8E" (normally only used for Super Smash Bros. Brawl's VC partitions)
    if (name[1] == '-' && name.size() == 6)
    {
      const u32 result = Common::swap32(reinterpret_cast<const u8*>(name.data() + 2));
      return static_cast<PartitionType>(result);
    }

    // e.g. "P0"
    if (std::all_of(name.cbegin() + 1, name.cend(), [](char c) { return c >= '0' && c <= '9'; }))
    {
      u32 result;
      if (TryParse(name.substr(1), &result))
        return static_cast<PartitionType>(result);
    }
  }

  return {};
}
Example #15
0
void HugeInteger::_fillDigits(const std::string &a_digits)
{
    size_t digit = {0};

    for (auto cit = a_digits.cbegin(); cit != a_digits.cend(); ++cit, ++digit)
        m_integers.at(digit) = *cit - '0';
}
Example #16
0
	// split a string into multiple chunks
	void ClientConsole::Split( const std::string &line, std::vector<std::string> &lines ) {
		const uint16_t fontSize = static_cast<uint16_t>( con_fontSize->GetInt32() );
		const real32_t lineWidth = view->width;

		ptrdiff_t startOffset = 0u;
		real32_t accumWidth = 0.0f;

		const char *p = line.c_str();
		for ( char c = *p; c != '\0'; c = *p++ ) {
			if ( c == '\t' ) {
				//FIXME: actually handle tab stops properly
				accumWidth += font->GetGlyphWidth( ' ', fontSize );
			}
			else {
				accumWidth += font->GetGlyphWidth( c, fontSize );
			}

			if ( accumWidth >= lineWidth ) {
				// splice and reset counters
				const ptrdiff_t endOffset = p - line.c_str();
				lines.push_back( std::string( line.cbegin() + startOffset, line.cbegin() + endOffset ) );
				startOffset = endOffset;
				accumWidth = 0.0f;
			}
		}

		// push the remainder of the line
		lines.push_back( std::string( line.cbegin() + startOffset, line.cend() ) );
	}
Example #17
0
	void add(const std::string& str)
	{
		auto strSize = (uint16_t)str.size();
		buffer.reserve(2+strSize);
		add(strSize);
		buffer.insert(buffer.end(), str.cbegin(), str.cend());
	}
Example #18
0
bool CompareLowerCase(std::string const& l, std::string const& r)
{
    return l.size() == r.size()
        && equal(l.cbegin(), l.cend(), r.cbegin(),
            [](std::string::value_type l1, std::string::value_type r1)
    { return toupper(l1) == toupper(r1); });
}
                void append_encoded_string(const std::string& data) {
                    boost::u8_to_u32_iterator<std::string::const_iterator> it(data.cbegin(), data.cbegin(), data.cend());
                    boost::u8_to_u32_iterator<std::string::const_iterator> end(data.cend(), data.cend(), data.cend());
                    boost::utf8_output_iterator<std::back_insert_iterator<std::string>> oit(std::back_inserter(*m_out));

                    for (; it != end; ++it) {
                        uint32_t c = *it;

                        // This is a list of Unicode code points that we let
                        // through instead of escaping them. It is incomplete
                        // and can be extended later.
                        // Generally we don't want to let through any character
                        // that has special meaning in the OPL format such as
                        // space, comma, @, etc. and any non-printing characters.
                        if ((0x0021 <= c && c <= 0x0024) ||
                            (0x0026 <= c && c <= 0x002b) ||
                            (0x002d <= c && c <= 0x003c) ||
                            (0x003e <= c && c <= 0x003f) ||
                            (0x0041 <= c && c <= 0x007e) ||
                            (0x00a1 <= c && c <= 0x00ac) ||
                            (0x00ae <= c && c <= 0x05ff)) {
                            *oit = c;
                        } else {
                            *m_out += '%';
                            output_formatted("%04x", c);
                        }
                    }
                }
Example #20
0
void NotationClass::xEscapeAndAppend(std::string &strAppendTo, const std::string &strSrc){
	strAppendTo.reserve(strAppendTo.size() + strSrc.size() * 2);
	for(auto iter = strSrc.cbegin(); iter != strSrc.cend(); ++iter){
		const char ch = *iter;
		switch(ch){
		case '\\':
		case '=':
		case '{':
		case '}':
		case ';':
			strAppendTo.push_back('\\');
			strAppendTo.push_back(ch);
			break;
		case '\n':
			strAppendTo.push_back('\\');
			strAppendTo.push_back('n');
			break;
		case '\b':
			strAppendTo.push_back('\\');
			strAppendTo.push_back('b');
			break;
		case '\r':
			strAppendTo.push_back('\\');
			strAppendTo.push_back('r');
			break;
		case '\t':
			strAppendTo.push_back('\\');
			strAppendTo.push_back('t');
			break;
		default:
			strAppendTo.push_back(ch);
			break;
		}
	}
}
Example #21
0
/** return the basename of a path. Example:
    /foo/bar/baz.txt returns baz.txt
 */
std::string path_basename(const std::string & path)
{
    auto slash_idx = path.find_last_of("/");
    if(slash_idx == std::string::npos) {
        return path;
    }
    return std::string(path.cbegin() + slash_idx + 1, path.cend());
}
Example #22
0
ConsoleCommand::ConsoleCommand(const std::string& str)
{
    std::regex e("^(?:/(\\S*)\\s*)?(.*)$");
    std::smatch sm;
    std::regex_match(str.cbegin(), str.cend(), sm, e);
    _command = sm[1];
    _content = sm[2];
}
Example #23
0
static bool PathEndsWith(const std::string& path, const std::string& suffix)
{
  if (suffix.size() > path.size())
    return false;

  std::string::const_iterator path_iterator = path.cend() - suffix.size();
  std::string::const_iterator suffix_iterator = suffix.cbegin();
  while (path_iterator != path.cend())
  {
    if (!PathCharactersEqual(*path_iterator, *suffix_iterator))
      return false;
    path_iterator++;
    suffix_iterator++;
  }

  return true;
}
Example #24
0
void Filter::ParseFilterString(const std::string& filter_str) {
    auto clause_begin = filter_str.cbegin();
    while (clause_begin != filter_str.cend()) {
        auto clause_end = std::find(clause_begin, filter_str.cend(), ' ');

        // If clause isn't empty
        if (clause_end != clause_begin) {
            ParseFilterRule(clause_begin, clause_end);
        }

        if (clause_end != filter_str.cend()) {
            // Skip over the whitespace
            ++clause_end;
        }
        clause_begin = clause_end;
    }
}
Example #25
0
// (static)
bool StringHelper::is_iequal(
    const std::string& a,
    const std::string& b)
{
    auto result = std::mismatch(
        a.cbegin(),
        a.cend(),
        b.cbegin(),
        [] (char char_a, char char_b)
        {
            return
                Internals::get_ctype_facet().tolower(char_a) ==
                Internals::get_ctype_facet().tolower(char_b);
        }
    );

    return result.first == a.cend();
}
Example #26
0
bool isdigit(const std::string & str)
{
    return str.size() == std::count_if(str.cbegin(),
                                       str.cend(),
    [](const std::string::value_type & c) {
        return isdigit(c);
    }
                                      );
}
bool StringUtil::hasAllUniqueCharacters(const std::string& str) {
	auto begin = str.cbegin();
	auto end = str.cend();
	for (; begin != end; begin++) {
		if (find(begin +1, end, *begin) != end)
			return false;
	}
	return true;
}
Example #28
0
size_t compute(const std::string& sequence_1, const std::string& sequence_2)
{
    if (sequence_1.size() != sequence_2.size())
    {
        throw std::domain_error("Sequences are not of same length");
    }
    return std::inner_product(sequence_1.cbegin(), sequence_1.cend(), sequence_2.cbegin(), 0,
                              std::plus<size_t>(), std::not_equal_to<char>());
}
Example #29
0
int wordScore(const std::string& word, const int n)
{
	int sum = 0;
	for (auto itr = word.cbegin(); itr != word.cend(); ++itr) {
		if (*itr != '"')
			sum += *itr - 'A' + 1;
	}
	return sum * n;
}
Example #30
0
bool NFA::simulate(std::string s)
{
	std::deque<State *> states = start->closure();
	for (auto it = s.cbegin(); it != s.cend();)
	{
		//TODO::step(states, *it);
	}
	return false;
}