From 0b0d241140baa888bb92ef9db8c1a143f62bdca5 Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Sat, 24 Apr 2021 13:05:20 +0200 Subject: [PATCH] Pass String arguments by reference according to #302 --- README.md | 6 +++--- src/OLEDDisplay.cpp | 8 ++++---- src/OLEDDisplay.h | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2d0351eb..70e92a46 100644 --- a/README.md +++ b/README.md @@ -231,19 +231,19 @@ void drawXbm(int16_t x, int16_t y, int16_t width, int16_t height, const uint8_t ## Text operations ``` C++ -void drawString(int16_t x, int16_t y, String text); +void drawString(int16_t x, int16_t y, const String &text); // Draws a String with a maximum width at the given location. // If the given String is wider than the specified width // The text will be wrapped to the next line at a space or dash -void drawStringMaxWidth(int16_t x, int16_t y, int16_t maxLineWidth, String text); +void drawStringMaxWidth(int16_t x, int16_t y, int16_t maxLineWidth, const String &text); // Returns the width of the const char* with the current // font settings uint16_t getStringWidth(const char* text, uint16_t length); // Convencience method for the const char version -uint16_t getStringWidth(String text); +uint16_t getStringWidth(const String &text); // Specifies relative to which anchor point // the text is rendered. Available constants: diff --git a/src/OLEDDisplay.cpp b/src/OLEDDisplay.cpp index b5471d1b..469e2dc6 100644 --- a/src/OLEDDisplay.cpp +++ b/src/OLEDDisplay.cpp @@ -606,7 +606,7 @@ void OLEDDisplay::drawStringInternal(int16_t xMove, int16_t yMove, char* text, u } -void OLEDDisplay::drawString(int16_t xMove, int16_t yMove, String strUser) { +void OLEDDisplay::drawString(int16_t xMove, int16_t yMove, const String &strUser) { uint16_t lineHeight = pgm_read_byte(fontData + HEIGHT_POS); // char* text must be freed! @@ -644,7 +644,7 @@ void OLEDDisplay::drawStringf( int16_t x, int16_t y, char* buffer, String format drawString( x, y, buffer ); } -void OLEDDisplay::drawStringMaxWidth(int16_t xMove, int16_t yMove, uint16_t maxLineWidth, String strUser) { +void OLEDDisplay::drawStringMaxWidth(int16_t xMove, int16_t yMove, uint16_t maxLineWidth, const String &strUser) { uint16_t firstChar = pgm_read_byte(fontData + FIRST_CHAR_POS); uint16_t lineHeight = pgm_read_byte(fontData + HEIGHT_POS); @@ -707,7 +707,7 @@ uint16_t OLEDDisplay::getStringWidth(const char* text, uint16_t length) { return max(maxWidth, stringWidth); } -uint16_t OLEDDisplay::getStringWidth(String strUser) { +uint16_t OLEDDisplay::getStringWidth(const String &strUser) { char* text = utf8ascii(strUser); uint16_t length = strlen(text); uint16_t width = getStringWidth(text, length); @@ -1074,7 +1074,7 @@ void inline OLEDDisplay::drawInternal(int16_t xMove, int16_t yMove, int16_t widt } // You need to free the char! -char* OLEDDisplay::utf8ascii(String str) { +char* OLEDDisplay::utf8ascii(const String &str) { uint16_t k = 0; uint16_t length = str.length() + 1; diff --git a/src/OLEDDisplay.h b/src/OLEDDisplay.h index 27815171..982b794e 100644 --- a/src/OLEDDisplay.h +++ b/src/OLEDDisplay.h @@ -243,7 +243,7 @@ class OLEDDisplay : public Stream { /* Text functions */ // Draws a string at the given location - void drawString(int16_t x, int16_t y, String text); + void drawString(int16_t x, int16_t y, const String &text); // Draws a formatted string (like printf) at the given location void drawStringf(int16_t x, int16_t y, char* buffer, String format, ... ); @@ -251,14 +251,14 @@ class OLEDDisplay : public Stream { // Draws a String with a maximum width at the given location. // If the given String is wider than the specified width // The text will be wrapped to the next line at a space or dash - void drawStringMaxWidth(int16_t x, int16_t y, uint16_t maxLineWidth, String text); + void drawStringMaxWidth(int16_t x, int16_t y, uint16_t maxLineWidth, const String &text); // Returns the width of the const char* with the current // font settings uint16_t getStringWidth(const char* text, uint16_t length); // Convencience method for the const char version - uint16_t getStringWidth(String text); + uint16_t getStringWidth(const String &text); // Specifies relative to which anchor point // the text is rendered. Available constants: @@ -378,7 +378,7 @@ class OLEDDisplay : public Stream { void sendInitCommands(); // converts utf8 characters to extended ascii - char* utf8ascii(String s); + char* utf8ascii(const String &s); void inline drawInternal(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const uint8_t *data, uint16_t offset, uint16_t bytesInData) __attribute__((always_inline));