Remove unused code
This commit is contained in:
parent
0fc1bd961f
commit
b3c3b4c729
@ -1080,182 +1080,6 @@ namespace StringUtils
|
||||
return url_without_protocol;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Breaks the text so that each line is smaller than max_width with the current settings.
|
||||
* The result is put into output, a vector of strings, with each line having its own string */
|
||||
// TODO : try to get rid of the complications induced by wchar
|
||||
void breakText(const std::wstring& input, std::vector<std::wstring> &output,
|
||||
unsigned int max_width, irr::gui::IGUIFont* font, bool right_to_left)
|
||||
{
|
||||
output.clear();
|
||||
|
||||
// We need to use a wstring to get wchar_t later
|
||||
std::wstring work_copy = input;
|
||||
|
||||
// For right to left, we reverse the order of the wchars.
|
||||
// Then, we apply the same operation at the end on the line strings.
|
||||
// As we don't break on multi-wchar symbols,
|
||||
// the second reverse step will put them back in the correct order.
|
||||
if (right_to_left)
|
||||
std::reverse(work_copy.begin(), work_copy.end());
|
||||
|
||||
wchar_t c;
|
||||
unsigned int index = 0;
|
||||
// The index of the last character to include before the linebreak
|
||||
unsigned int break_index = 0;
|
||||
irr::core::dimension2du area;
|
||||
// Algorithm :
|
||||
// 1)If the index exceed the work_copy string size, go to step 7a)
|
||||
// unless it is 0, in which case there is nothing to copy at all and it exits immediately.
|
||||
// 2)We look at the character at the index
|
||||
// 3)We check if the current character is a linebreak. If yes, go to step 7a)
|
||||
// 4)We check if it is part of a multi-wchar unicode character.
|
||||
// If we are in a multi-wchar unicode character, go to step 6.
|
||||
// We don't check if it's the first or second one, because those characters
|
||||
// are not a suitable break-point anyway. In theory, this doesn't work well
|
||||
// if only such characters are used, but this is a silly theoretical case.
|
||||
// 5a)We check if the length of the string including the new character is < max_width
|
||||
// 5b)If it is smaller, and a suitable character to break, we update the break_index
|
||||
// 5c)If it is bigger, we go to step 7
|
||||
// 6)If no linebreak has been requested, increment the index, and return to step 1)
|
||||
// 7a)If a linebreak has been requested, we push back the substring from 0 to break_index,
|
||||
// and truncate that substring from work_copy. The index is reset to 0.
|
||||
// If break_index is 0, we cut the string at the current index.
|
||||
// 7b)If we have broken the whole input text into lines, we quit the loop.
|
||||
while(true)
|
||||
{
|
||||
// We have reached the end of the string, we just need to push back the current content
|
||||
// Step 1
|
||||
if (index >= work_copy.size())
|
||||
{
|
||||
if (index==0)
|
||||
break;
|
||||
|
||||
break_index = index-1;
|
||||
goto push_text; // Avoid complicating things with checks on every single step
|
||||
}
|
||||
|
||||
// Step 2
|
||||
c = work_copy[index];
|
||||
|
||||
// Step 3
|
||||
if (c == L'\r' || c == L'\n')
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
work_copy.erase(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
break_index = index;
|
||||
if (c == L'\r' && index+1 < work_copy.size() && work_copy[index+1] == L'\n') // Windows breaks
|
||||
work_copy.erase(index+1);
|
||||
goto push_text;
|
||||
}
|
||||
|
||||
// Step 4
|
||||
if (partOfLongUnicodeChar(c))
|
||||
goto next_loop_no_push;
|
||||
|
||||
// Step 5
|
||||
|
||||
// index+1 because index starts at 0 and substr takes initial pos and length as arguments
|
||||
area = font->getDimension(work_copy.substr(0,index+1).c_str());
|
||||
if (area.Width < max_width)
|
||||
{
|
||||
if (breakable(c))
|
||||
break_index = index;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not enough room to draw even 1 character, abort
|
||||
if (index==0)
|
||||
{
|
||||
Log::error("StringUtils",
|
||||
"Not enough width to fit a character. Width is %i.", max_width);
|
||||
break;
|
||||
}
|
||||
|
||||
goto push_text;
|
||||
}
|
||||
|
||||
// Step 6
|
||||
next_loop_no_push:
|
||||
index++;
|
||||
continue;
|
||||
|
||||
// Step 7
|
||||
push_text:
|
||||
|
||||
// Calculate break index depending on max text length if there is no
|
||||
// breakable character
|
||||
if (break_index == 0)
|
||||
{
|
||||
for (unsigned int i = 0; i < work_copy.size(); i++)
|
||||
{
|
||||
std::wstring text = work_copy.substr(0, i+1);
|
||||
unsigned int width = font->getDimension(text.c_str()).Width;
|
||||
|
||||
if (width > max_width)
|
||||
break;
|
||||
|
||||
break_index++;
|
||||
}
|
||||
|
||||
break_index = std::max(0, (int)break_index - 1);
|
||||
}
|
||||
|
||||
// To include the char at break_index, we need a length of break_index+1
|
||||
std::wstring text_line = work_copy.substr(0,break_index+1);
|
||||
output.push_back(text_line);
|
||||
|
||||
// If the line break was the last char of the input string
|
||||
if (work_copy.size() == break_index+1)
|
||||
{
|
||||
// The text is entirely treated
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
work_copy = work_copy.substr(break_index+1); // All the string except the pushed back part
|
||||
index = 0;
|
||||
break_index = 0;
|
||||
}
|
||||
} // While(true) - active until the whole string has been broken and copied
|
||||
if (right_to_left)
|
||||
{
|
||||
for (unsigned int i=0;i<output.size();i++)
|
||||
{
|
||||
std::reverse(output[i].begin(), output[i].end());
|
||||
}
|
||||
}
|
||||
} // breakText
|
||||
|
||||
/* This function checks if a char is suitable to break lines.
|
||||
* Based on the function found at irrlicht/include/utfwrapping.h */
|
||||
bool breakable (wchar_t c)
|
||||
{
|
||||
if ((c > 12287 && c < 40960) || //Common CJK words
|
||||
(c > 44031 && c < 55204) || //Hangul
|
||||
(c > 63743 && c < 64256) || //More Chinese
|
||||
c == 45 || c == 173 || c == L' ' || //Hypen, soft hyphen and white space
|
||||
c == 47 || c == 92) //Slash and blackslash
|
||||
return true;
|
||||
return false;
|
||||
} // breakable
|
||||
|
||||
/* This function checks if a char is part of a two wchars unicode symbol */
|
||||
bool partOfLongUnicodeChar (wchar_t c)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if (c >= 0x10000)
|
||||
return true;
|
||||
return false;
|
||||
#else
|
||||
return false; //A wchar_t in Linux or Mac uses 32 bits
|
||||
#endif
|
||||
} // partOfLongUnicodeChar
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
irr::core::stringw utf32ToWide(const std::u32string& input)
|
||||
{
|
||||
|
@ -285,10 +285,6 @@ namespace StringUtils
|
||||
std::string findAndReplace(const std::string& source, const std::string& find, const std::string& replace);
|
||||
std::string removeWhitespaces(const std::string& input);
|
||||
irr::core::stringw getReadableFileSize(uint64_t n);
|
||||
void breakText(const std::wstring& input, std::vector<std::wstring> &output,
|
||||
unsigned int max_width, irr::gui::IGUIFont* font, bool right_to_left=false);
|
||||
bool breakable (wchar_t c);
|
||||
bool partOfLongUnicodeChar (wchar_t c);
|
||||
irr::core::stringw utf32ToWide(const std::u32string& input);
|
||||
std::u32string wideToUtf32(const irr::core::stringw& input);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user