add last backwards-compatible version
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include "StdAfx.h"
|
||||
#include "stdafx.h"
|
||||
#include "create_directory_helper.h"
|
||||
#include <pfc/pathUtils.h>
|
||||
|
||||
namespace create_directory_helper
|
||||
{
|
||||
@@ -118,38 +117,29 @@ namespace create_directory_helper
|
||||
}
|
||||
|
||||
pfc::string create_directory_helper::sanitize_formatted_path(pfc::stringp formatted, bool allowWC) {
|
||||
return sanitize_formatted_path_ex(formatted, allowWC, pfc::io::path::charReplaceDefault);
|
||||
};
|
||||
|
||||
pfc::string create_directory_helper::sanitize_formatted_path_ex(pfc::stringp formatted, bool allowWC, charReplace_t replace) {
|
||||
pfc::string out;
|
||||
t_size curSegBase = 0;
|
||||
for (t_size walk = 0; ; ++walk) {
|
||||
for(t_size walk = 0; ; ++walk) {
|
||||
const char c = formatted[walk];
|
||||
const bool end = (c == 0);
|
||||
if (end || pfc::io::path::isSeparator(c)) {
|
||||
if (curSegBase < walk) {
|
||||
pfc::string seg(formatted + curSegBase, walk - curSegBase);
|
||||
out = pfc::io::path::combine(out, pfc::io::path::validateFileName(seg, allowWC, end /*preserve ext*/, replace));
|
||||
pfc::string seg( formatted + curSegBase, walk - curSegBase );
|
||||
out = pfc::io::path::combine(out, pfc::io::path::validateFileName(seg, allowWC, end /*preserve ext*/));
|
||||
}
|
||||
if (end) break;
|
||||
if ( end ) break;
|
||||
curSegBase = walk + 1;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
void create_directory_helper::format_filename_ex(const metadb_handle_ptr & handle, titleformat_hook * p_hook, titleformat_object::ptr spec, const char * suffix, pfc::string_base & out) {
|
||||
format_filename_ex(handle, p_hook, spec, suffix, out, pfc::io::path::charReplaceDefault);
|
||||
}
|
||||
|
||||
void create_directory_helper::format_filename_ex(const metadb_handle_ptr & handle,titleformat_hook * p_hook,titleformat_object::ptr spec,const char * suffix, pfc::string_base & out, charReplace_t replace) {
|
||||
void create_directory_helper::format_filename_ex(const metadb_handle_ptr & handle,titleformat_hook * p_hook,titleformat_object::ptr spec,const char * suffix, pfc::string_base & out) {
|
||||
pfc::string_formatter formatted;
|
||||
titleformat_text_filter_myimpl filter;
|
||||
filter.m_replace = replace;
|
||||
handle->format_title(p_hook,formatted,spec,&filter);
|
||||
formatted << suffix;
|
||||
out = sanitize_formatted_path_ex(formatted, false, replace).ptr();
|
||||
out = sanitize_formatted_path(formatted).ptr();
|
||||
}
|
||||
void create_directory_helper::format_filename(const metadb_handle_ptr & handle,titleformat_hook * p_hook,titleformat_object::ptr spec,pfc::string_base & out) {
|
||||
format_filename_ex(handle, p_hook, spec, "", out);
|
||||
@@ -164,30 +154,16 @@ void create_directory_helper::format_filename(const metadb_handle_ptr & handle,t
|
||||
}
|
||||
}
|
||||
|
||||
static bool substSanity(const char * subst) {
|
||||
if (subst == nullptr) return false;
|
||||
for (size_t w = 0; subst[w]; ++w) {
|
||||
if (pfc::io::path::isSeparator(subst[w])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void create_directory_helper::titleformat_text_filter_myimpl::write(const GUID & p_inputType,pfc::string_receiver & p_out,const char * p_data,t_size p_dataLength) {
|
||||
if (p_inputType == titleformat_inputtypes::meta) {
|
||||
pfc::string_formatter temp;
|
||||
for(t_size walk = 0; walk < p_dataLength; ++walk) {
|
||||
char c = p_data[walk];
|
||||
if (c == 0) break;
|
||||
const char * subst = nullptr;
|
||||
if (pfc::io::path::isSeparator(c)) {
|
||||
if (m_replace) {
|
||||
const char * proposed = m_replace(c);
|
||||
if (substSanity(proposed)) subst = proposed;
|
||||
}
|
||||
if (subst == nullptr) subst = "-";
|
||||
c = '-';
|
||||
}
|
||||
if (subst != nullptr) temp.add_string(subst);
|
||||
else temp.add_byte(c);
|
||||
temp.add_byte(c);
|
||||
}
|
||||
p_out.add_string(temp);
|
||||
} else p_out.add_string(p_data,p_dataLength);
|
||||
|
||||
Reference in New Issue
Block a user