changed the way how prefixes are added to urls
instead at the end we adding a prefix before an extension, e.g: filename_(2).jpg
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* Copyright (c) 2008-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -1161,30 +1161,55 @@ bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool cl
|
||||
}
|
||||
|
||||
|
||||
// if there is not an extension it returns a pointer to the last '\0' character
|
||||
// if there is no an extension it returns a pointer to the last '\0' character
|
||||
const wchar_t * GetFileExt(const wchar_t * name)
|
||||
{
|
||||
size_t i, ilast;
|
||||
const wchar_t * dot_ptr = nullptr;
|
||||
|
||||
// looking for the end of the name
|
||||
for(i=0 ; name[i] != 0 ; ++i);
|
||||
for( ; *name != 0 ; ++name)
|
||||
{
|
||||
if( *name == '.' )
|
||||
{
|
||||
dot_ptr = name;
|
||||
}
|
||||
}
|
||||
|
||||
if( i == 0 )
|
||||
return name; // ops, the name is empty
|
||||
return dot_ptr ? dot_ptr + 1 : name;
|
||||
}
|
||||
|
||||
// remember the end of the string
|
||||
ilast = i;
|
||||
|
||||
// looking for the last dot
|
||||
for(--i ; i>0 && name[i] != '.' ; --i);
|
||||
void PrepareNewFileName(const wchar_t * src, const wchar_t * postfix, std::wstring & res, bool clear_res)
|
||||
{
|
||||
bool has_ext = false;
|
||||
const wchar_t * ext = GetFileExt(src);
|
||||
|
||||
if( name[i] != '.' )
|
||||
return name + ilast; // ops, there is not a dot
|
||||
if( clear_res )
|
||||
res.clear();
|
||||
|
||||
// the extensions starts from i+1
|
||||
// and can be empty (if the last character is a dot)
|
||||
size_t len = ext - src;
|
||||
|
||||
return name + i + 1;
|
||||
if( len > 0 )
|
||||
{
|
||||
if( *(ext-1) == '.' )
|
||||
{
|
||||
len -= 1;
|
||||
has_ext = true;
|
||||
}
|
||||
}
|
||||
|
||||
res.append(src, len);
|
||||
res.append(postfix);
|
||||
|
||||
if( has_ext )
|
||||
res.append(1, '.');
|
||||
|
||||
res.append(ext);
|
||||
}
|
||||
|
||||
|
||||
void PrepareNewFileName(const std::wstring & src, const std::wstring & postfix, std::wstring & res, bool clear_res)
|
||||
{
|
||||
return PrepareNewFileName(src.c_str(), postfix.c_str(), res, clear_res);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -77,6 +77,7 @@ double Tod(const wchar_t * str);
|
||||
|
||||
// if the buffer is too small it will be terminated at the beginning (empty string)
|
||||
// and the function returns false
|
||||
// IMPROVEME now we can use Toa from Pikotools
|
||||
template<class CharType>
|
||||
bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10)
|
||||
{
|
||||
@@ -663,6 +664,11 @@ bool GetUTF8File(const std::wstring & file_path, std::wstring & content, bool cl
|
||||
|
||||
|
||||
const wchar_t * GetFileExt(const wchar_t * name);
|
||||
|
||||
void PrepareNewFileName(const wchar_t * src, const wchar_t * postfix, std::wstring & res, bool clear_res = true);
|
||||
void PrepareNewFileName(const std::wstring & src, const std::wstring & postfix, std::wstring & res, bool clear_res = true);
|
||||
|
||||
|
||||
int SelectFileType(const wchar_t * file_name);
|
||||
int SelectFileType(const std::wstring & file_name);
|
||||
|
||||
|
Reference in New Issue
Block a user