示例#1
0
文件: utils.cpp 项目: niemyjski/cli
void append_path(pal::string_t& path1, const pal::char_t* path2)
{
    if (pal::is_path_rooted(path2))
    {
        path1.assign(path2);
    }
    else
    {
        if (path1.back() != DIR_SEPARATOR)
        {
            path1.push_back(DIR_SEPARATOR);
        }
        path1.append(path2);
    }
}
示例#2
0
文件: tpafile.cpp 项目: krwq/cli-1
bool read_field(pal::string_t line, int& offset, pal::string_t& value_recv)
{
	// The first character should be a '"'
	if (line[offset] != '"')
	{
		trace::error(_X("error reading TPA file"));
		return false;
	}
	offset++;

	// Set up destination buffer (it can't be bigger than the original line)
	pal::char_t buf[PATH_MAX];
	auto buf_offset = 0;

	// Iterate through characters in the string
	for (; offset < line.length(); offset++)
	{
		// Is this a '\'?
		if (line[offset] == '\\')
		{
			// Skip this character and read the next character into the buffer
			offset++;
			buf[buf_offset] = line[offset];
		}
		// Is this a '"'?
		else if (line[offset] == '\"')
		{
			// Done! Advance to the pointer after the input
			offset++;
			break;
		}
		else
		{
			// Take the character
			buf[buf_offset] = line[offset];
		}
		buf_offset++;
	}
	buf[buf_offset] = '\0';
	value_recv.assign(buf);

	// Consume the ',' if we have one
	if (line[offset] == ',')
	{
		offset++;
	}
	return true;
}