[ion/utf8_helper] HasCodePoint

This commit is contained in:
Léa Saviot
2019-09-09 12:13:01 +02:00
parent b4f9cbf4b3
commit d9f650d283
6 changed files with 14 additions and 7 deletions

View File

@@ -48,7 +48,7 @@ void App::Snapshot::setOpt(const char * name, char * value) {
if (strcmp(name, "script") == 0) {
m_scriptStore.deleteAllScripts();
char * separator = const_cast<char *>(UTF8Helper::CodePointSearch(value, ':'));
if (!separator) {
if (*separator == 0) {
return;
}
*separator = 0;

View File

@@ -49,8 +49,7 @@ bool ListController::textFieldDidFinishEditing(TextField * textField, const char
assert(textField != nullptr);
// Compute the new name
size_t textLength = strlen(text);
bool textIncludesTheta = UTF8Helper::CodePointSearch(text, UCodePointGreekSmallLetterTheta) != nullptr;
size_t argumentLength = textIncludesTheta ? Function::k_parenthesedThetaArgumentByteLength : Function::k_parenthesedXNTArgumentByteLength;
size_t argumentLength = UTF8Helper::HasCodePoint(text, UCodePointGreekSmallLetterTheta) ? Function::k_parenthesedThetaArgumentByteLength : Function::k_parenthesedXNTArgumentByteLength;
constexpr int maxBaseNameSize = Function::k_maxNameWithArgumentSize;
char baseName[maxBaseNameSize];
if (textLength <= argumentLength) {

View File

@@ -26,8 +26,8 @@ Responder * TextFieldFunctionTitleCell::responder() {
void TextFieldFunctionTitleCell::setEditing(bool editing) {
Container::activeApp()->setFirstResponder(&m_textField);
const char * previousText = m_textField.text();
bool titleIncludesTheta = *(UTF8Helper::CodePointSearch(previousText, UCodePointGreekSmallLetterTheta)) != 0;
m_textField.setExtensionLength(titleIncludesTheta ? Shared::Function::k_parenthesedThetaArgumentByteLength : Shared::Function::k_parenthesedXNTArgumentByteLength);
int extensionLength = UTF8Helper::HasCodePoint(previousText, UCodePointGreekSmallLetterTheta) ? Shared::Function::k_parenthesedThetaArgumentByteLength : Shared::Function::k_parenthesedXNTArgumentByteLength;
m_textField.setExtensionLength(extensionLength);
m_textField.setEditing(true);
m_textField.setText(previousText);
}

View File

@@ -13,6 +13,9 @@ int CountOccurrences(const char * s, CodePoint c);
* null terminating char otherwise. */
const char * CodePointSearch(const char * s, CodePoint c);
// Returns true if the text had the code point
bool HasCodePoint(const char * s, CodePoint c);
/* Returns the first occurence of a code point that is not c in a string,
* stopping at the null-terminating char or the start of string. */
const char * NotCodePointSearch(const char * s, CodePoint c, bool goingLeft = false, const char * initialPosition = nullptr);

View File

@@ -55,6 +55,11 @@ const char * CodePointSearch(const char * s, CodePoint c) {
return currentPointer;
}
bool HasCodePoint(const char * s, CodePoint c) {
assert(c != 0);
return *CodePointSearch(s, c) != 0;
}
const char * NotCodePointSearch(const char * s, CodePoint c, bool goingLeft, const char * initialPosition) {
if (goingLeft && initialPosition == s) {
return s;
@@ -144,7 +149,7 @@ void RemoveCodePoint(char * buffer, CodePoint c, const char * * pointerToUpdate,
} else {
assert(stoppingPosition != nullptr);
// Find the null-terminating code point
const char * nullTermination = CodePointSearch(currentPointer, UCodePointNull);
const char * nullTermination = currentPointer + strlen(currentPointer);
/* Copy what remains of the buffer after the stopping position for code
* point removal */
memmove(buffer + bufferIndex, stoppingPosition, nullTermination - stoppingPosition + 1);

View File

@@ -416,7 +416,7 @@ void Expression::SetEncounteredComplex(bool encounterComplex) {
}
Preferences::ComplexFormat Expression::UpdatedComplexFormatWithTextInput(Preferences::ComplexFormat complexFormat, const char * textInput) {
if (complexFormat == Preferences::ComplexFormat::Real && *(UTF8Helper::CodePointSearch(textInput, UCodePointMathematicalBoldSmallI)) != 0) {
if (complexFormat == Preferences::ComplexFormat::Real && UTF8Helper::HasCodePoint(textInput, UCodePointMathematicalBoldSmallI)) {
return Preferences::ComplexFormat::Cartesian;
}
return complexFormat;