mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion/utf8_helper] Signedness and capitalization
Change-Id: I3451a206fbd45a490eea0115621c07abb868344a
This commit is contained in:
committed by
Émilie Feral
parent
bd068312d9
commit
28d18dd6a5
@@ -33,7 +33,7 @@ const char * Clipboard::storedText() {
|
||||
UTF8Helper::TextPair("\x12\x13", "\x12\x11\x13"),
|
||||
};
|
||||
|
||||
UTF8Helper::tryAndReplacePatternsInStringByPatterns(m_textBuffer, TextField::maxBufferSize(), (UTF8Helper::TextPair *) &textPairs, numberOfPairs, true);
|
||||
UTF8Helper::TryAndReplacePatternsInStringByPatterns(m_textBuffer, TextField::maxBufferSize(), (UTF8Helper::TextPair *) &textPairs, numberOfPairs, true);
|
||||
return m_textBuffer;
|
||||
}
|
||||
|
||||
@@ -42,5 +42,5 @@ void Clipboard::reset() {
|
||||
}
|
||||
|
||||
void Clipboard::replaceCharForPython(bool entersPythonApp) {
|
||||
UTF8Helper::tryAndReplacePatternsInStringByPatterns((char *)m_textBuffer, TextField::maxBufferSize(), (UTF8Helper::TextPair *)&PythonTextPairs, NumberOfPythonTextPairs, entersPythonApp);
|
||||
}
|
||||
UTF8Helper::TryAndReplacePatternsInStringByPatterns((char *)m_textBuffer, TextField::maxBufferSize(), (UTF8Helper::TextPair *)&PythonTextPairs, NumberOfPythonTextPairs, entersPythonApp);
|
||||
}
|
||||
|
||||
@@ -44,10 +44,10 @@ void RemoveCodePoint(char * buffer, CodePoint c, const char * * indexToUpdate =
|
||||
/* Slides a string by a number of chars. If slidingSize < 0, the string is slided
|
||||
* to the left losing the first chars. Returns true if successful.
|
||||
* Exemples :
|
||||
* slideStringByNumberOfChar("12345", 2, 7) gives "1212345"
|
||||
* slideStringByNumberOfChar("12345", 2, 5) gives "12123"
|
||||
* slideStringByNumberOfChar("12345", -2, 5) gives "34545"*/
|
||||
bool slideStringByNumberOfChar(char * text, int slidingSize, int textMaxLength);
|
||||
* SlideStringByNumberOfChar("12345", 2, 7) gives "1212345"
|
||||
* SlideStringByNumberOfChar("12345", 2, 5) gives "12123"
|
||||
* SlideStringByNumberOfChar("12345", -2, 5) gives "34545"*/
|
||||
bool SlideStringByNumberOfChar(char * text, int slidingSize, size_t textMaxLength);
|
||||
|
||||
/* Looks for patterns in a string. If a pattern is found, it is replaced by
|
||||
* the one associated in the TextPair struct.
|
||||
@@ -58,7 +58,7 @@ bool slideStringByNumberOfChar(char * text, int slidingSize, int textMaxLength);
|
||||
* - stoppingPosition allows partial replacement in the string.
|
||||
*
|
||||
* Ensure null termination of the string or set the value of stoppingPosition*/
|
||||
void tryAndReplacePatternsInStringByPatterns(char * text, int textMaxSize, TextPair * textPairs, int numberOfPairs, bool firstToSecond, const char * * indexToUpdate = nullptr, const char * stoppingPosition = nullptr);
|
||||
void TryAndReplacePatternsInStringByPatterns(char * text, int textMaxSize, TextPair * textPairs, int numberOfPairs, bool firstToSecond, const char * * indexToUpdate = nullptr, const char * stoppingPosition = nullptr);
|
||||
|
||||
/* Copy src into dst until end of dst or code point c, with null termination. Return the length of the copy */
|
||||
size_t CopyUntilCodePoint(char * dst, size_t dstSize, const char * src, CodePoint c);
|
||||
|
||||
@@ -138,11 +138,11 @@ void RemoveCodePoint(char * buffer, CodePoint c, const char * * pointerToUpdate,
|
||||
UTF8Decoder::CodePointToChars(c, pattern, codePointCharSize);
|
||||
pattern[codePointCharSize] = '\0';
|
||||
TextPair pair(pattern, "");
|
||||
tryAndReplacePatternsInStringByPatterns(buffer, strlen(buffer), &pair, 1, true, pointerToUpdate, stoppingPosition);
|
||||
TryAndReplacePatternsInStringByPatterns(buffer, strlen(buffer), &pair, 1, true, pointerToUpdate, stoppingPosition);
|
||||
}
|
||||
|
||||
bool slideStringByNumberOfChar(char * text, int slidingSize, int textMaxLength) {
|
||||
int lenText = strlen(text);
|
||||
bool SlideStringByNumberOfChar(char * text, int slidingSize, size_t textMaxLength) {
|
||||
size_t lenText = strlen(text);
|
||||
if (lenText + slidingSize > textMaxLength || lenText + slidingSize < 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -158,10 +158,10 @@ bool slideStringByNumberOfChar(char * text, int slidingSize, int textMaxLength)
|
||||
/* Replaces the first chars of a string by other ones. If the sizes are different
|
||||
* the rest of the string will be moved right after the replacement chars.
|
||||
* If successful returns true.*/
|
||||
static bool replaceFirstCharsByPattern(char * text, int lengthOfPatternToRemove, const char * replacementPattern, int textMaxLength) {
|
||||
int lengthOfReplacementPattern = strlen(replacementPattern);
|
||||
if (lengthOfPatternToRemove <= strlen(text) && slideStringByNumberOfChar(text, lengthOfReplacementPattern-lengthOfPatternToRemove, textMaxLength)) {
|
||||
for (int i = 0; i < lengthOfReplacementPattern; i++) {
|
||||
static bool replaceFirstCharsByPattern(char * text, size_t lengthOfPatternToRemove, const char * replacementPattern, size_t textMaxLength) {
|
||||
size_t lengthOfReplacementPattern = strlen(replacementPattern);
|
||||
if (lengthOfPatternToRemove <= strlen(text) && SlideStringByNumberOfChar(text, lengthOfReplacementPattern-lengthOfPatternToRemove, textMaxLength)) {
|
||||
for (size_t i = 0; i < lengthOfReplacementPattern; i++) {
|
||||
text[i] = replacementPattern[i];
|
||||
}
|
||||
return true;
|
||||
@@ -169,7 +169,7 @@ static bool replaceFirstCharsByPattern(char * text, int lengthOfPatternToRemove,
|
||||
return false;
|
||||
}
|
||||
|
||||
void tryAndReplacePatternsInStringByPatterns(char * text, int textMaxLength, TextPair * textPairs, int numberOfPairs, bool firstToSecond, const char * * pointerToUpdate, const char * stoppingPosition) {
|
||||
void TryAndReplacePatternsInStringByPatterns(char * text, int textMaxLength, TextPair * textPairs, int numberOfPairs, bool firstToSecond, const char * * pointerToUpdate, const char * stoppingPosition) {
|
||||
size_t i = 0;
|
||||
size_t iPrev = 0;
|
||||
size_t textLength = strlen(text);
|
||||
|
||||
@@ -166,7 +166,7 @@ QUIZ_CASE(ion_utf8_remove_code_point) {
|
||||
void assert_slide_string_by_number_of_char_gives(const char * string, int slidingSize, bool successResult, const char * stringResult = nullptr) {
|
||||
char buffer[bufferSize];
|
||||
strlcpy(buffer, string, bufferSize);
|
||||
bool success = UTF8Helper::slideStringByNumberOfChar((char *)buffer, slidingSize, bufferSize);
|
||||
bool success = UTF8Helper::SlideStringByNumberOfChar((char *)buffer, slidingSize, bufferSize);
|
||||
quiz_assert(success == successResult);
|
||||
if (successResult) {
|
||||
quiz_assert(strncmp(buffer, stringResult, bufferSize) == 0);
|
||||
@@ -187,7 +187,7 @@ QUIZ_CASE(ion_utf8_move_string_from_index_by_number_of_char) {
|
||||
}
|
||||
|
||||
void assert_try_and_replace_pattern_in_string_by_pattern_gives(char * buffer, int bufferSize, UTF8Helper::TextPair * textPairs, int numberOfPairs, bool firstToSecond, const char * stringResult, const char ** indexToUpdate = nullptr, const char * indexToUpdateResult = nullptr, const char * stoppingPosition = nullptr) {
|
||||
UTF8Helper::tryAndReplacePatternsInStringByPatterns(buffer, bufferSize, textPairs, numberOfPairs, firstToSecond, indexToUpdate, stoppingPosition);
|
||||
UTF8Helper::TryAndReplacePatternsInStringByPatterns(buffer, bufferSize, textPairs, numberOfPairs, firstToSecond, indexToUpdate, stoppingPosition);
|
||||
quiz_assert(strncmp(buffer, stringResult, bufferSize) == 0);
|
||||
if (indexToUpdateResult != nullptr) {
|
||||
quiz_assert(*indexToUpdate == indexToUpdateResult);
|
||||
|
||||
Reference in New Issue
Block a user