mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-30 04:00:02 +02:00
Use std::min and std::max
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "script.h"
|
||||
#include "variable_box_controller.h"
|
||||
#include <apps/i18n.h>
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
#include <escher/metric.h>
|
||||
#include <apps/global_preferences.h>
|
||||
@@ -15,8 +16,6 @@ extern "C" {
|
||||
|
||||
namespace Code {
|
||||
|
||||
static inline int minInt(int x, int y) { return x < y ? x : y; }
|
||||
|
||||
static const char * sStandardPromptText = ">>> ";
|
||||
|
||||
ConsoleController::ConsoleController(Responder * parentResponder, App * pythonDelegate, ScriptStore * scriptStore
|
||||
@@ -487,7 +486,7 @@ void ConsoleController::autoImportScript(Script script, bool force) {
|
||||
|
||||
/* Copy the script name without the extension ".py". The '.' is overwritten
|
||||
* by the null terminating char. */
|
||||
int copySizeWithNullTerminatingZero = minInt(k_maxImportCommandSize - currentChar, strlen(scriptName) - strlen(ScriptStore::k_scriptExtension));
|
||||
int copySizeWithNullTerminatingZero = std::min(k_maxImportCommandSize - currentChar, strlen(scriptName) - strlen(ScriptStore::k_scriptExtension));
|
||||
assert(copySizeWithNullTerminatingZero >= 0);
|
||||
assert(copySizeWithNullTerminatingZero <= k_maxImportCommandSize - currentChar);
|
||||
strlcpy(command+currentChar, scriptName, copySizeWithNullTerminatingZero);
|
||||
|
||||
@@ -4,11 +4,10 @@
|
||||
#include <apps/i18n.h>
|
||||
#include <apps/global_preferences.h>
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace Code {
|
||||
|
||||
static inline int minInt(int x, int y) { return x < y ? x : y; }
|
||||
|
||||
ConsoleEditCell::ConsoleEditCell(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, TextFieldDelegate * delegate) :
|
||||
HighlightCell(),
|
||||
Responder(parentResponder),
|
||||
@@ -70,7 +69,7 @@ const char * ConsoleEditCell::shiftCurrentTextAndClear() {
|
||||
char * textFieldBuffer = const_cast<char *>(m_textField.text());
|
||||
char * newTextPosition = textFieldBuffer + 1;
|
||||
assert(previousBufferSize > 0);
|
||||
size_t copyLength = minInt(previousBufferSize - 1, strlen(textFieldBuffer));
|
||||
size_t copyLength = std::min(previousBufferSize - 1, strlen(textFieldBuffer));
|
||||
memmove(newTextPosition, textFieldBuffer, copyLength);
|
||||
newTextPosition[copyLength] = 0;
|
||||
textFieldBuffer[0] = 0;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#include "console_store.h"
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace Code {
|
||||
|
||||
static inline int minInt(int x, int y) { return x < y ? x : y; }
|
||||
|
||||
void ConsoleStore::startNewSession() {
|
||||
if (k_historySize < 1) {
|
||||
return;
|
||||
@@ -103,7 +102,7 @@ const char * ConsoleStore::push(const char marker, const char * text) {
|
||||
i = indexOfNullMarker();
|
||||
}
|
||||
m_history[i] = marker;
|
||||
strlcpy(&m_history[i+1], text, minInt(k_historySize-(i+1),textLength+1));
|
||||
strlcpy(&m_history[i+1], text, std::min(k_historySize-(i+1),textLength+1));
|
||||
m_history[i+1+textLength+1] = 0;
|
||||
return &m_history[i+1];
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ extern "C" {
|
||||
#include "py/lexer.h"
|
||||
}
|
||||
#include <stdlib.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace Code {
|
||||
|
||||
@@ -21,8 +22,6 @@ constexpr KDColor StringColor = KDColor::RGB24(0x032f62);
|
||||
constexpr KDColor BackgroundColor = KDColorWhite;
|
||||
constexpr KDColor HighlightColor = Palette::Select;
|
||||
|
||||
static inline const char * minPointer(const char * x, const char * y) { return x < y ? x : y; }
|
||||
|
||||
static inline KDColor TokenColor(mp_token_kind_t tokenKind) {
|
||||
if (tokenKind == MP_TOKEN_STRING) {
|
||||
return StringColor;
|
||||
@@ -84,7 +83,7 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char
|
||||
line,
|
||||
fromColumn,
|
||||
lineStart,
|
||||
minPointer(text + byteLength, lineEnd) - lineStart,
|
||||
std::min(text + byteLength, lineEnd) - lineStart,
|
||||
StringColor,
|
||||
BackgroundColor,
|
||||
selectionStart,
|
||||
@@ -107,7 +106,7 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char
|
||||
line,
|
||||
fromColumn,
|
||||
spacesStart,
|
||||
minPointer(text + byteLength, firstNonSpace) - spacesStart,
|
||||
std::min(text + byteLength, firstNonSpace) - spacesStart,
|
||||
StringColor,
|
||||
BackgroundColor,
|
||||
selectionStart,
|
||||
@@ -135,7 +134,7 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char
|
||||
line,
|
||||
UTF8Helper::GlyphOffsetAtCodePoint(text, tokenEnd),
|
||||
tokenEnd,
|
||||
minPointer(text + byteLength, tokenFrom) - tokenEnd,
|
||||
std::min(text + byteLength, tokenFrom) - tokenEnd,
|
||||
StringColor,
|
||||
BackgroundColor,
|
||||
selectionStart,
|
||||
|
||||
Reference in New Issue
Block a user