示例#1
0
文件: vector.hpp 项目: niXman/yarmi
std::ostream& operator<< (std::ostream &s, const std::vector<T, Allocator> &o) {
    s << detail::array_open_symbol;
    for ( auto cur = o.begin(), end = o.end(); cur != end; ++cur ) {
        jsonify(s, *cur);
        if ( std::next(cur) != end )
            s << detail::default_delimiter;
    }
    return s << detail::array_close_symbol;
}
示例#2
0
//take a file list and convert it into json
//int_remove_length is the number of characters to remove from each line
//useful if your list is like:
//  /path/to/file1
//  /path/to/file2
//and you want it like:
//  file1
//  file2
char *file_list_to_json (char *str_content, int int_remove_length) {
	char *str_return = NULL;
	char *str_temp = NULL;
	char *str_temp_json = NULL;
	ERROR_NORESPONSE("int_remove_length: %d", int_remove_length);
	ERROR_CAT_CSTR(str_return, "");
	char *ptr_content = str_content + int_remove_length + 1; // + 1 means remove /
	if (*(ptr_content - 1) == '\n') { //if we are at a newline,
		//then the first line must be the full length to remove, so skip that line
		ptr_content = ptr_content + int_remove_length + 1; // + 1 means remove \n
	}
	int int_length;
	int int_done = 1;
	char *ptr_end_content = str_content + strlen(str_content);
	while (int_done > 0) {
		if (ptr_content <= ptr_end_content && strchr(ptr_content, '\n') != 0) {
			int_length = (strchr(ptr_content, '\n') - ptr_content);
			if (int_length > 0) {
				ERROR_SALLOC(str_temp, int_length + 1);
				memcpy(str_temp, ptr_content, int_length);
				str_temp[int_length] = 0;
				str_temp_json = jsonify(str_temp);
				SFREE(str_temp);
				if (strlen(str_return) > 0) {
					ERROR_CAT_APPEND(str_return, ",", str_temp_json);
				} else {
					ERROR_CAT_APPEND(str_return, str_temp_json);
				}
				ERROR_NORESPONSE(">%s|%s|%s<", str_return, str_temp_json, ptr_content);
				SFREE(str_temp_json);
			}
			ptr_content = strchr(ptr_content, '\n') + int_remove_length + 1 + 1; // + 1 means remove \n // + 1 means remove /
		} else {
			int_done = 0;
		}
	}
	return str_return;
error:
	SFREE(str_temp);
	SFREE(str_temp_json);
	SFREE(str_return);
	return NULL;
}