mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
Replacing custom String.toInt() function with a call to atol().
This commit is contained in:
parent
4d3b263738
commit
32388c908f
@ -1,8 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Character analysis operators
|
Character analysis operators
|
||||||
|
|
||||||
Examples using the character analysis operators
|
Examples using the character analysis operators.
|
||||||
from WCharacter.h, by Hernando Barragan.
|
|
||||||
Send any byte and the sketch will tell you about it.
|
Send any byte and the sketch will tell you about it.
|
||||||
|
|
||||||
created 29 Nov 2010
|
created 29 Nov 2010
|
||||||
@ -11,8 +10,6 @@
|
|||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <WCharacter.h> // include the character analysis library
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Open serial communications:
|
// Open serial communications:
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -13,9 +13,6 @@
|
|||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the character conversion functions:
|
|
||||||
#include <WCharacter.h>
|
|
||||||
|
|
||||||
String inString = ""; // string to hold input
|
String inString = ""; // string to hold input
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
@ -20,9 +20,6 @@
|
|||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the character conversion functions:
|
|
||||||
#include <WCharacter.h>
|
|
||||||
|
|
||||||
String inString = ""; // string to hold input
|
String inString = ""; // string to hold input
|
||||||
int currentColor = 0;
|
int currentColor = 0;
|
||||||
int red, green, blue = 0;
|
int red, green, blue = 0;
|
||||||
|
@ -20,8 +20,7 @@
|
|||||||
#ifndef Character_h
|
#ifndef Character_h
|
||||||
#define Character_h
|
#define Character_h
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include "WProgram.h"
|
|
||||||
|
|
||||||
// WCharacter.h prototypes
|
// WCharacter.h prototypes
|
||||||
inline boolean isAlphaNumeric(int c) __attribute__((always_inline));
|
inline boolean isAlphaNumeric(int c) __attribute__((always_inline));
|
||||||
@ -117,8 +116,8 @@ inline boolean isPunct(int c)
|
|||||||
|
|
||||||
|
|
||||||
// Checks for white-space characters. For the avr-libc library,
|
// Checks for white-space characters. For the avr-libc library,
|
||||||
// these are: space, formfeed (’\f’), newline (’\n’), carriage
|
// these are: space, formfeed ('\f'), newline ('\n'), carriage
|
||||||
// return (’\r’), horizontal tab (’\t’), and vertical tab (’\v’).
|
// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
|
||||||
inline boolean isSpace(int c)
|
inline boolean isSpace(int c)
|
||||||
{
|
{
|
||||||
return ( isspace (c) == 0 ? false : true);
|
return ( isspace (c) == 0 ? false : true);
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "wiring.h"
|
#include "wiring.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
#include "WCharacter.h"
|
||||||
#include "WString.h"
|
#include "WString.h"
|
||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
|
|
||||||
|
@ -437,16 +437,5 @@ void String::toCharArray(char *buf, unsigned int bufsize)
|
|||||||
|
|
||||||
|
|
||||||
long String::toInt() {
|
long String::toInt() {
|
||||||
String temp = _buffer;
|
return atol(_buffer);
|
||||||
long value = 0;
|
|
||||||
|
|
||||||
for (unsigned int charPos = 0; charPos < _length; charPos++) {
|
|
||||||
int thisChar = temp[charPos];
|
|
||||||
if (isdigit(thisChar)) {
|
|
||||||
value *= 10;
|
|
||||||
value += (thisChar - '0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user