Skip to content

Commit 32388c9

Browse files
committed
Replacing custom String.toInt() function with a call to atol().
1 parent 4d3b263 commit 32388c9

File tree

6 files changed

+6
-26
lines changed

6 files changed

+6
-26
lines changed

build/shared/examples/8.Strings/CharacterAnalysis/CharacterAnalysis.pde

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/*
22
Character analysis operators
33
4-
Examples using the character analysis operators
5-
from WCharacter.h, by Hernando Barragan.
4+
Examples using the character analysis operators.
65
Send any byte and the sketch will tell you about it.
76
87
created 29 Nov 2010
@@ -11,8 +10,6 @@
1110
This example code is in the public domain.
1211
*/
1312

14-
#include <WCharacter.h> // include the character analysis library
15-
1613
void setup() {
1714
// Open serial communications:
1815
Serial.begin(9600);

build/shared/examples/8.Strings/StringToInt/StringToInt.pde

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
This example code is in the public domain.
1414
*/
1515

16-
// include the character conversion functions:
17-
#include <WCharacter.h>
18-
1916
String inString = ""; // string to hold input
2017

2118
void setup() {

build/shared/examples/8.Strings/StringToIntRGB/StringToIntRGB.pde

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
This example code is in the public domain.
2121
*/
2222

23-
// include the character conversion functions:
24-
#include <WCharacter.h>
25-
2623
String inString = ""; // string to hold input
2724
int currentColor = 0;
2825
int red, green, blue = 0;

hardware/arduino/cores/arduino/WCharacter.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
#ifndef Character_h
2121
#define Character_h
2222

23-
24-
#include "WProgram.h"
23+
#include <ctype.h>
2524

2625
// WCharacter.h prototypes
2726
inline boolean isAlphaNumeric(int c) __attribute__((always_inline));
@@ -117,8 +116,8 @@ inline boolean isPunct(int c)
117116

118117

119118
// Checks for white-space characters. For the avr-libc library,
120-
// these are: space, formfeed (’\f’), newline (’\n’), carriage
121-
// return (’\r’), horizontal tab (’\t’), and vertical tab (’\v’).
119+
// these are: space, formfeed ('\f'), newline ('\n'), carriage
120+
// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
122121
inline boolean isSpace(int c)
123122
{
124123
return ( isspace (c) == 0 ? false : true);

hardware/arduino/cores/arduino/WProgram.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "wiring.h"
1111

1212
#ifdef __cplusplus
13+
#include "WCharacter.h"
1314
#include "WString.h"
1415
#include "HardwareSerial.h"
1516

hardware/arduino/cores/arduino/WString.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -437,16 +437,5 @@ void String::toCharArray(char *buf, unsigned int bufsize)
437437

438438

439439
long String::toInt() {
440-
String temp = _buffer;
441-
long value = 0;
442-
443-
for (unsigned int charPos = 0; charPos < _length; charPos++) {
444-
int thisChar = temp[charPos];
445-
if (isdigit(thisChar)) {
446-
value *= 10;
447-
value += (thisChar - '0');
448-
}
449-
}
450-
451-
return value;
440+
return atol(_buffer);
452441
}

0 commit comments

Comments
 (0)