Skip to content

Commit 5930c1c

Browse files
authored
Pass String arguments by reference (#342)
1 parent 946f351 commit 5930c1c

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,19 @@ void drawXbm(int16_t x, int16_t y, int16_t width, int16_t height, const uint8_t
231231
## Text operations
232232

233233
``` C++
234-
void drawString(int16_t x, int16_t y, String text);
234+
void drawString(int16_t x, int16_t y, const String &text);
235235

236236
// Draws a String with a maximum width at the given location.
237237
// If the given String is wider than the specified width
238238
// The text will be wrapped to the next line at a space or dash
239-
void drawStringMaxWidth(int16_t x, int16_t y, int16_t maxLineWidth, String text);
239+
void drawStringMaxWidth(int16_t x, int16_t y, int16_t maxLineWidth, const String &text);
240240

241241
// Returns the width of the const char* with the current
242242
// font settings
243243
uint16_t getStringWidth(const char* text, uint16_t length);
244244

245245
// Convencience method for the const char version
246-
uint16_t getStringWidth(String text);
246+
uint16_t getStringWidth(const String &text);
247247

248248
// Specifies relative to which anchor point
249249
// the text is rendered. Available constants:

src/OLEDDisplay.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ void OLEDDisplay::drawStringInternal(int16_t xMove, int16_t yMove, char* text, u
606606
}
607607

608608

609-
void OLEDDisplay::drawString(int16_t xMove, int16_t yMove, String strUser) {
609+
void OLEDDisplay::drawString(int16_t xMove, int16_t yMove, const String &strUser) {
610610
uint16_t lineHeight = pgm_read_byte(fontData + HEIGHT_POS);
611611

612612
// char* text must be freed!
@@ -644,7 +644,7 @@ void OLEDDisplay::drawStringf( int16_t x, int16_t y, char* buffer, String format
644644
drawString( x, y, buffer );
645645
}
646646

647-
void OLEDDisplay::drawStringMaxWidth(int16_t xMove, int16_t yMove, uint16_t maxLineWidth, String strUser) {
647+
void OLEDDisplay::drawStringMaxWidth(int16_t xMove, int16_t yMove, uint16_t maxLineWidth, const String &strUser) {
648648
uint16_t firstChar = pgm_read_byte(fontData + FIRST_CHAR_POS);
649649
uint16_t lineHeight = pgm_read_byte(fontData + HEIGHT_POS);
650650

@@ -707,7 +707,7 @@ uint16_t OLEDDisplay::getStringWidth(const char* text, uint16_t length) {
707707
return max(maxWidth, stringWidth);
708708
}
709709

710-
uint16_t OLEDDisplay::getStringWidth(String strUser) {
710+
uint16_t OLEDDisplay::getStringWidth(const String &strUser) {
711711
char* text = utf8ascii(strUser);
712712
uint16_t length = strlen(text);
713713
uint16_t width = getStringWidth(text, length);
@@ -1074,7 +1074,7 @@ void inline OLEDDisplay::drawInternal(int16_t xMove, int16_t yMove, int16_t widt
10741074
}
10751075

10761076
// You need to free the char!
1077-
char* OLEDDisplay::utf8ascii(String str) {
1077+
char* OLEDDisplay::utf8ascii(const String &str) {
10781078
uint16_t k = 0;
10791079
uint16_t length = str.length() + 1;
10801080

src/OLEDDisplay.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,22 +243,22 @@ class OLEDDisplay : public Stream {
243243
/* Text functions */
244244

245245
// Draws a string at the given location
246-
void drawString(int16_t x, int16_t y, String text);
246+
void drawString(int16_t x, int16_t y, const String &text);
247247

248248
// Draws a formatted string (like printf) at the given location
249249
void drawStringf(int16_t x, int16_t y, char* buffer, String format, ... );
250250

251251
// Draws a String with a maximum width at the given location.
252252
// If the given String is wider than the specified width
253253
// The text will be wrapped to the next line at a space or dash
254-
void drawStringMaxWidth(int16_t x, int16_t y, uint16_t maxLineWidth, String text);
254+
void drawStringMaxWidth(int16_t x, int16_t y, uint16_t maxLineWidth, const String &text);
255255

256256
// Returns the width of the const char* with the current
257257
// font settings
258258
uint16_t getStringWidth(const char* text, uint16_t length);
259259

260260
// Convencience method for the const char version
261-
uint16_t getStringWidth(String text);
261+
uint16_t getStringWidth(const String &text);
262262

263263
// Specifies relative to which anchor point
264264
// the text is rendered. Available constants:
@@ -378,7 +378,7 @@ class OLEDDisplay : public Stream {
378378
void sendInitCommands();
379379

380380
// converts utf8 characters to extended ascii
381-
char* utf8ascii(String s);
381+
char* utf8ascii(const String &s);
382382

383383
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));
384384

0 commit comments

Comments
 (0)