aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/WString.cpp
AgeCommit message (Collapse)Author
2016-07-12Make String::move of an invalidated String result in an invalidated StringSandeep Mistry
2015-07-16Check for __cplusplus >= 201103L as well as __GXX_EXPERIMENTAL_CXX0X__Matthijs Kooijman
Gcc 4.8 defines __cplusplus as 201103L, so we can check for that now. It still also defines __GXX_EXPERIMENTAL_CXX0X__, but this could help on other compilers, or if gcc ever decides to stop defining the experimental macro.
2014-09-10Fix off-by-one in String::substringMatthijs Kooijman
When checking the `left` argument, it previously allowed having left == len. However, this means the substring starts one past the last character in the string and should return the empty string. In practice, this already worked correctly, because buffer[len] contains the trailing nul, so it would (re)assign the empty string to `out`. However, fixing this check makes it a bit more logical, and prevents a fairly unlikely out-of-buffer write (to address 0x0) when calling substring on an invalidated String: String bar = (char*)NULL; bar.substring(0, 0);
2014-09-10Simplify String::remove(unsigned int)Matthijs Kooijman
Previously, this method calculated the length of the string from the given index onwards. However, the other remove() method called already contains code for this calculation, which is used when the count passed in is too big. This means we can just pass in a very big count that is guaranteed to point past the end of the string, shrinking the remove method by a few bytes.
2014-09-10Fix bounds check in String::remove()Matthijs Kooijman
Previously, if you passed in a very big index and/or count, the `index + count` could overflow, making the count be used as-is instead of being truncated (causing the string to be updated wrongly and potentially writing to arbitrary memory locations). We can rewrite the comparison to use `len - index` instead. Since we know that index < len, we are sure this subtraction does not overflow, regardless of what values of index and count we pass in. As an added bonus, the `len - index` value already needed be calculated inside the if, so this saves a few instructions in the generated code. To illustrate this problem, consider this code: String foo = "foo"; Serial.println(foo.length()); // Prints 3 foo.remove(1, 65535); // Should remove all but first character Serial.println(foo.length()); // Prints 4 without this patch Not shown in this is example is that some arbitrary memory is written as well.
2014-09-10Remove unneeded check in String::remove(unsigned int)Matthijs Kooijman
This check already happens in the remove(unsigned int, unsigned int) method that is caled, so there is no need to also check this here.
2014-01-01Improved portability of String class (maniacbug)Cristian Maglie
2013-12-31Use PGM_P instead of prog_charMatthijs Kooijman
On later versions of avr-libc, prog_char is deprecated. In 0acebeeff48 the one occurence of prog_char was replaced by "char PROGMEM", which is not entirely correct (PROGMEM is supposed to be an attribute on a variable, not on a type, even though this is how things work in older libc versions). However, in 1130fede3a2 a few new occurences of prog_char are introduced, which break compilation on newer libc versions again. This commit changes all these pointer types to use the PGM_P macro from <avr/pgmspace.h>. This macro is just "const char *" in newer libc versions and "const prog_char *" in older versions, so it should always work. References #795
2013-09-03Fixed String class regression after f80c6c5f35cddcf4761a3c97feb8504425e9d27dCristian Maglie
This should make explicit String-from-integer constructor working again: int a = 10; String(a, 4);
2013-08-20Removed unused flags from String (free 1 byte of SRAM)Cristian Maglie
2013-06-28String: fixed number of whitespaces in concat() methodsCristian Maglie
2013-06-21String: changed default to 2 decimal digitsCristian Maglie
2013-06-06Fixed buffer overflow on String class (Paul Stoffregen)Cristian Maglie
2013-06-06Merged various bugfix / improvements to String class.Cristian Maglie
Merge branch 'master' into ide-1.5.x
2013-06-06Added support for Flash string on String class.Cristian Maglie
2013-06-06String class: removed deep copy on substring method.Cristian Maglie
Small code cleanup.
2013-06-06add String.toFloatTevin Zhang
2013-06-05Added remove methods to WStringRyan Esteves
2012-01-02Fixing warnings (unsigned comparisons to 0). (maniacbug)David A. Mellis
2011-10-25Bug fix in replace().David A. Mellis
http://code.google.com/p/arduino/issues/detail?id=694
2011-10-10Fixing more warnings (Paul Stoffregen).David A. Mellis
2011-03-31Restoring concatenation of built-in types with String.David A. Mellis
2011-03-26String: removing implicit numeric conversions and new approach to "if (s)".David A. Mellis
This makes explicit the String constructors that take numeric types and chars and removes the versions of concat() and operator=() and operator+() that accept numberic types. It also replaces the operator bool() with a operator that converts to a function pointer. This allows for uses like "if (s)" but not "s + 123". See: http://www.artima.com/cppsource/safebool.html. This allowed removing the disambiguating operator+() functions and relying solely on StringSumHelper and anonymous temporaries once again. Also, now treating unsigned char's like int when constructing Strings from them, i.e. String(byte(65)) is now "65" not "A". This is consistent with the new behavior of Serial.print(byte).
2011-03-19Return an invalid string (not a partial one) when operator+() fails.David A. Mellis
2011-03-18Starting to distinguish between empty strings and invalid (null) ones.David A. Mellis
2011-03-13Moving move() to __GXX_EXPERIMENTAL_CXX0X__ only, adding operator bool().David A. Mellis
2011-03-12Modifying String.concat() to return success or failure, not this.David A. Mellis
Which means you can't chain multiple concat() calls together, but you can check if they succeeded or not.
2011-03-11Don't return the string when modifying its value.David A. Mellis
Changing toLowerCase(), toUpperCase(), trim() and replace() to return void instead of a reference to the string that's just been changed. That way, it's clear that the functions modify the string they've been called on.
2011-03-11Renaming append() back to concat().David A. Mellis
2011-03-11Removing F("string") syntax for now.David A. Mellis
We should probably add something like this back in later, but I want to do one thing at a time. This removes the __FlashStringHelper class as well.
2011-03-11Rewrite of the String class by Paul Stoffregen.David A. Mellis
http://www.pjrc.com/teensy/string_class_experimental.html
2011-03-01Renamed WProgram.h to Arduino.h.David A. Mellis
2010-12-11Changing String append to use realloc(); thanks to Paul Stoffregen.David A. Mellis
http://code.google.com/p/arduino/issues/detail?id=332
2010-12-03Replacing custom String.toInt() function with a call to atol().David A. Mellis
2010-11-29Redoing 448222e4b65e0cf44dfc0c494f7f76901f1fabea without all the extra files.David A. Mellis
Adds toInt() to String, WCharacter.h (from Wiring), and an SD Datalogger example.
2010-11-29Revert "added toInt() function to WString".David A. Mellis
This reverts commit 448222e4b65e0cf44dfc0c494f7f76901f1fabea.
2010-11-29added toInt() function to WStringTom Igoe
2010-08-28Changing String::toCharArray() and getBytes() to accept a buffer, rather ↵David A. Mellis
than return one. That way they don't expose the internal representation of the String class, allowing future optimization. Thanks to Paul Stoffregen.
2010-08-28Returning a reference to a dummy character for indices beyond the string ↵David A. Mellis
length (in operator[]).
2010-08-18Adding some basic error checking to the String class (i.e. checking for a ↵David A. Mellis
non-null buffer before modifying its contents).
2010-07-27Reverting changes to String class and modifying to allow + and += to work on ↵David A. Mellis
more types.
2010-07-27removed append() from String libraryTom Igoe
2010-07-27checked in Xiaoyang Feng's changes to String libraryTom Igoe
2010-07-27Checked in Xiaoyang's changes to String libraryTom Igoe
2010-07-05whitespace.David A. Mellis
2010-07-04Modifying String from new/delete to malloc()/free(). Also #include'ing ↵David A. Mellis
WString.h from WProgram.h.
2010-07-04Adding WString.h and WString.cpp straight from Wiring (r. 726). Won't ↵David A. Mellis
actually work yet.