mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/shared] Share PadWithSpaces method
This commit is contained in:
committed by
EmilieNumworks
parent
e17658181d
commit
a886c0fb32
25
apps/shared/text_helpers.cpp
Normal file
25
apps/shared/text_helpers.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "text_helpers.h"
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_helper.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Shared {
|
||||
namespace TextHelpers {
|
||||
|
||||
void PadWithSpaces(char * buffer, int bufferSize, int * currentNumberOfChar, int maxGlyphLengthWithPadding) {
|
||||
assert(*currentNumberOfChar <= bufferSize);
|
||||
size_t currentGlyphLength = UTF8Helper::StringGlyphLength(buffer, *currentNumberOfChar);
|
||||
bool addedPadding = false;
|
||||
assert(UTF8Decoder::CharSizeOfCodePoint(' ') == 1);
|
||||
while (currentGlyphLength < maxGlyphLengthWithPadding && *currentNumberOfChar < bufferSize) {
|
||||
*currentNumberOfChar = *currentNumberOfChar + UTF8Decoder::CodePointToChars(' ', buffer + *currentNumberOfChar, bufferSize - *currentNumberOfChar);
|
||||
addedPadding = true;
|
||||
currentGlyphLength++;
|
||||
}
|
||||
if (addedPadding) {
|
||||
buffer[*currentNumberOfChar-1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user