mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[ion/utf8_helper] HasCodePoint
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user