bool data_stream::write_line(const dynamic_string& str) { if (!str.is_empty()) return write(str.get_ptr(), str.get_len()) == str.get_len(); return true; }
bool file_utils::write_string_to_file(const char *pPath, const dynamic_string &str) { cfile_stream stream; if (!stream.open(pPath, cDataStreamWritable)) return false; if (str.get_len()) stream.write(str.get_ptr(), str.get_len()); return !stream.get_error(); }
bool file_utils::create_directories_from_full_path(const dynamic_string &fullpath) { bool got_unc = false; VOGL_NOTE_UNUSED(got_unc); dynamic_string cur_path; const int l = fullpath.get_len(); int n = 0; while (n < l) { const char c = fullpath.get_ptr()[n]; const bool sep = is_path_separator(c); const bool back_sep = is_path_separator(cur_path.back()); const bool is_last_char = (n == (l - 1)); if (((sep) && (!back_sep)) || (is_last_char)) { if ((is_last_char) && (!sep)) cur_path.append_char(c); bool valid = !cur_path.is_empty(); #if defined(PLATFORM_WINDOWS) // reject obvious stuff (drives, beginning of UNC paths): // c:\b\cool // \\machine\blah // \cool\blah if ((cur_path.get_len() == 2) && (cur_path[1] == ':')) valid = false; else if ((cur_path.get_len() >= 2) && (cur_path[0] == '\\') && (cur_path[1] == '\\')) { if (!got_unc) valid = false; got_unc = true; } else if (cur_path == "\\") valid = false; #endif if (cur_path == "/") valid = false; if (valid) { create_directory(cur_path.get_ptr()); } } cur_path.append_char(c); n++; } return true; }
void get_command_line_as_single_string(dynamic_string& cmd_line, int argc, char *argv[]) { argc, argv; #if false && CRNLIB_USE_WIN32_API // THIS DOES NOT WORK PROPERLY, ADDING TOO MANY QUOTES, SO WE IGNORE IT. cmd_line.set(GetCommandLineA()); #else cmd_line.clear(); for (int i = 0; i < argc; i++) { dynamic_string tmp(argv[i]); if ((tmp.front() != '"') && (tmp.front() != '-') && (tmp.front() != '@')) tmp = "\"" + tmp + "\""; if (cmd_line.get_len()) cmd_line += " "; cmd_line += tmp; } #endif }
void get_command_line(dynamic_string& cmd_line, int argc, char *argv[]) { argc, argv; #if CRNLIB_USE_WIN32_API cmd_line.set(GetCommandLineA()); #else cmd_line.clear(); for (int i = 0; i < argc; i++) { dynamic_string tmp(argv[i]); if ((tmp.front() != '"') && (tmp.front() != '-') && (tmp.front() != '@')) tmp = "\"" + tmp + "\""; if (cmd_line.get_len()) cmd_line += " "; cmd_line += tmp; } #endif }
void file_utils::trim_trailing_seperator(dynamic_string &path) { if ((path.get_len()) && (is_path_separator(path.back()))) path.truncate(path.get_len() - 1); }