arduino_ci 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1553aff5cd187c7db5ea325fd2ee878914fae57692d70042f1ceb0a6cd184f18
4
- data.tar.gz: 8c948d1eec2967ee364fc2fa983bed1746dc1204089d2ea0f355ab27b0aa97f6
3
+ metadata.gz: 81bed39a97b584fc45ff028f60c9eeb50e24e929123e3af0ca9e6db48ffc5d1a
4
+ data.tar.gz: 4ee99e35584eaa5db713d80149b1ce7bead47f8e3ac74d1016e82fdb11f1b1c0
5
5
  SHA512:
6
- metadata.gz: 43bbc201c5d38e8852a71e3a0b4da85400d764fc2e4b248e0fd14f6d79c1111c4bc778aecdc7e49bea8c7c73e4417b28f4ae9d3e5c3ba4814768929bf5ae2c7b
7
- data.tar.gz: '069ce22a67dc335c5b1d97bdecc91476bf8f6484740b9acfd063e4c2741db0cfa808c5b5599dce970721f2d808825ebf0297857e88fe7a75bfa2611a4cda23bf'
6
+ metadata.gz: 64286125ad20ef12fda79a938d29f44d20751db0716144149a660afb350da73f08ef0b1d0494b1d472cac6d50d2cbdc48ce1e4697736f509fbc036adbb724ac1
7
+ data.tar.gz: 40620b0806a64191b00c84bdf86f546dd131a5cafdda8cc6da23e9cbd64235f88fa2b7aa9d580d5c05cb47da3f93dd0961f86a18dff344d68de7b7f428a673be
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/arduino_ci.svg)](https://rubygems.org/gems/arduino_ci)
2
2
  [![Build Status](https://travis-ci.org/ifreecarve/arduino_ci.svg)](https://travis-ci.org/ifreecarve/arduino_ci)
3
- [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/arduino_ci/0.1.5)
3
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/arduino_ci/0.1.6)
4
4
 
5
5
  # ArduinoCI Ruby gem (`arduino_ci`)
6
6
 
@@ -59,14 +59,6 @@ typedef unsigned int word;
59
59
 
60
60
 
61
61
 
62
- /*
63
- unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
64
- unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
65
-
66
- void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
67
- uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
68
-
69
- */
70
62
 
71
63
  // Get the bit location within the hardware port of the given virtual pin.
72
64
  // This comes from the pins_*.c file for the active board configuration.
@@ -74,40 +66,6 @@ uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
74
66
  #define analogInPinToBit(P) (P)
75
67
  #define digitalPinToInterrupt(P) (P)
76
68
 
77
- /*
78
- // On the ATmega1280, the addresses of some of the port registers are
79
- // greater than 255, so we can't store them in uint8_t's.
80
- extern const uint16_t PROGMEM port_to_mode_PGM[];
81
- extern const uint16_t PROGMEM port_to_input_PGM[];
82
- extern const uint16_t PROGMEM port_to_output_PGM[];
83
-
84
- extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
85
- // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
86
- extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
87
- extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
88
-
89
- // Get the bit location within the hardware port of the given virtual pin.
90
- // This comes from the pins_*.c file for the active board configuration.
91
- //
92
- // These perform slightly better as macros compared to inline functions
93
- //
94
- #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
95
- #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
96
- #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
97
- #define analogInPinToBit(P) (P)
98
- #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
99
- #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
100
- #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
101
-
102
- */
103
-
104
-
105
- /* TODO
106
- #include "WString.h"
107
- #include "HardwareSerial.h"
108
- #include "USBAPI.h"
109
- */
110
-
111
69
  // uint16_t makeWord(uint16_t w);
112
70
  // uint16_t makeWord(byte h, byte l);
113
71
  inline unsigned int makeWord(unsigned int w) { return w; }
@@ -115,41 +73,6 @@ inline unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8)
115
73
 
116
74
  #define word(...) makeWord(__VA_ARGS__)
117
75
 
118
- unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
119
- unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
120
-
121
- void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
122
- void noTone(uint8_t _pin);
123
-
124
-
125
- // BIG TODO ON THIS ONE
126
- // $ find . | grep pins_
127
- // ./arduino-1.8.5/hardware/arduino/avr/variants/circuitplay32u4/pins_arduino.h
128
- // ./arduino-1.8.5/hardware/arduino/avr/variants/eightanaloginputs/pins_arduino.h
129
- // ./arduino-1.8.5/hardware/arduino/avr/variants/ethernet/pins_arduino.h
130
- // ./arduino-1.8.5/hardware/arduino/avr/variants/gemma/pins_arduino.h
131
- // ./arduino-1.8.5/hardware/arduino/avr/variants/leonardo/pins_arduino.h
132
- // ./arduino-1.8.5/hardware/arduino/avr/variants/mega/pins_arduino.h
133
- // ./arduino-1.8.5/hardware/arduino/avr/variants/micro/pins_arduino.h
134
- // ./arduino-1.8.5/hardware/arduino/avr/variants/robot_control/pins_arduino.h
135
- // ./arduino-1.8.5/hardware/arduino/avr/variants/robot_motor/pins_arduino.h
136
- // ./arduino-1.8.5/hardware/arduino/avr/variants/standard/pins_arduino.h
137
- // ./arduino-1.8.5/hardware/arduino/avr/variants/yun/pins_arduino.h
138
- // #include "pins_arduino.h"
139
-
140
76
 
141
77
 
142
- /*
143
-
144
-
145
- // Communication
146
- serial
147
- stream
148
-
149
- // USB
150
- Keyboard
151
- Mouse
152
-
153
- */
154
-
155
78
 
@@ -1,5 +1,7 @@
1
1
  #pragma once
2
2
 
3
+ #include <avr/pgmspace.h>
4
+
3
5
  #define HIGH 0x1
4
6
  #define LOW 0x0
5
7
 
@@ -86,7 +86,7 @@ class PinHistory : public ObservableDataStream {
86
86
  // this sets the value of the pin authoritatively
87
87
  // so if there was a queue, dump it.
88
88
  // the actual "set" operation doesn't happen until the next read
89
- const T &operator=(const T& i) {
89
+ T operator=(const T& i) {
90
90
  qIn.clear();
91
91
  qOut.push(i);
92
92
  advertiseBit(qOut.back()); // not valid for all possible types but whatever
data/cpp/arduino/Print.h CHANGED
@@ -32,7 +32,6 @@ class Print
32
32
  virtual size_t write(uint8_t) = 0;
33
33
  size_t write(const char *str) { return str == NULL ? 0 : write((const uint8_t *)str, String(str).length()); }
34
34
 
35
- size_t write(const __FlashStringHelper *str) { return write((const char *)str); }
36
35
 
37
36
  virtual size_t write(const uint8_t *buffer, size_t size) {
38
37
  size_t n;
@@ -41,28 +40,30 @@ class Print
41
40
  }
42
41
  size_t write(const char *buffer, size_t size) { return write((const uint8_t *)buffer, size); }
43
42
 
44
- size_t print(const String &s) { return write(s.c_str(), s.length()); }
45
- size_t print(const char* str) { return print(String(str)); }
46
- size_t print(char c) { return print(String(c)); }
47
- size_t print(unsigned char b, int base) { return print(String(b, base)); }
48
- size_t print(int n, int base) { return print(String(n, base)); }
49
- size_t print(unsigned int n, int base) { return print(String(n, base)); }
50
- size_t print(long n, int base) { return print(String(n, base)); }
51
- size_t print(unsigned long n, int base) { return print(String(n, base)); }
52
- size_t print(double n, int digits) { return print(String(n, digits)); }
53
- size_t print(const Printable& x) { return x.printTo(*this); }
43
+ size_t print(const String &s) { return write(s.c_str(), s.length()); }
44
+ size_t print(const __FlashStringHelper *str) { return print(reinterpret_cast<PGM_P>(str)); }
45
+ size_t print(const char* str) { return print(String(str)); }
46
+ size_t print(char c) { return print(String(c)); }
47
+ size_t print(unsigned char b, int base) { return print(String(b, base)); }
48
+ size_t print(int n, int base) { return print(String(n, base)); }
49
+ size_t print(unsigned int n, int base) { return print(String(n, base)); }
50
+ size_t print(long n, int base) { return print(String(n, base)); }
51
+ size_t print(unsigned long n, int base) { return print(String(n, base)); }
52
+ size_t print(double n, int digits) { return print(String(n, digits)); }
53
+ size_t print(const Printable& x) { return x.printTo(*this); }
54
54
 
55
- size_t println(void) { return print("\r\n"); }
56
- size_t println(const String &s) { return print(s) + println(); }
57
- size_t println(const char* c) { return println(String(c)); }
58
- size_t println(char c) { return println(String(c)); }
59
- size_t println(unsigned char b, int base) { return println(String(b, base)); }
60
- size_t println(int num, int base) { return println(String(num, base)); }
61
- size_t println(unsigned int num, int base) { return println(String(num, base)); }
62
- size_t println(long num, int base) { return println(String(num, base)); }
63
- size_t println(unsigned long num, int base) { return println(String(num, base)); }
64
- size_t println(double num, int digits) { return println(String(num, digits)); }
65
- size_t println(const Printable& x) { return print(x) + println(); }
55
+ size_t println(void) { return print("\r\n"); }
56
+ size_t println(const String &s) { return print(s) + println(); }
57
+ size_t println(const __FlashStringHelper *str) { return println(reinterpret_cast<PGM_P>(str)); }
58
+ size_t println(const char* c) { return println(String(c)); }
59
+ size_t println(char c) { return println(String(c)); }
60
+ size_t println(unsigned char b, int base) { return println(String(b, base)); }
61
+ size_t println(int num, int base) { return println(String(num, base)); }
62
+ size_t println(unsigned int num, int base) { return println(String(num, base)); }
63
+ size_t println(long num, int base) { return println(String(num, base)); }
64
+ size_t println(unsigned long num, int base) { return println(String(num, base)); }
65
+ size_t println(double num, int digits) { return println(String(num, digits)); }
66
+ size_t println(const Printable& x) { return print(x) + println(); }
66
67
 
67
68
  virtual void flush() { }
68
69
 
@@ -10,16 +10,19 @@ class SoftwareSerial : public Stream
10
10
  private:
11
11
  int mPinIn;
12
12
  int mPinOut;
13
- bool mInverse;
14
13
  bool mIsListening;
15
14
  GodmodeState* mState;
16
15
  unsigned long mOffset; // bits to offset stream
17
16
  bool bigEndian;
18
17
 
19
18
  public:
20
- SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false) {
19
+ // @TODO this is public for now to avoid a compiler warning
20
+ bool mInvertLogic; // @TODO not sure how to implement yet
21
+
22
+ SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool invertLogic = false) {
21
23
  mPinIn = receivePin;
22
24
  mPinOut = transmitPin;
25
+ mIsListening = invertLogic;
23
26
  mIsListening = false;
24
27
  mOffset = 0; // godmode starts with 1 bit in the queue
25
28
  mState = GODMODE();
@@ -1,7 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  #include <stdlib.h>
4
- #include <string>
4
+ #include <string.h>
5
5
  #include <algorithm>
6
6
  #include <iostream>
7
7
  #include "AvrMath.h"
@@ -9,24 +9,16 @@
9
9
 
10
10
  typedef std::string string;
11
11
 
12
- //typedef const char __FlashStringHelper;
13
12
  class __FlashStringHelper;
14
13
  #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
15
14
 
16
15
  // Compatibility with string class
17
16
  class String: public string
18
17
  {
19
- public:
20
-
21
- // allow "string s; if (s) {}"
22
- // http://www.artima.com/cppsource/safebool.html
23
- typedef void (String::*TTDNSCstring)() const;
24
- void ttdnsc() const {}
25
- operator TTDNSCstring() const { return &String::ttdnsc; }
26
-
27
18
  private:
28
- static const char* digit(int val) {
29
- static const char* bank = "0123456789ABCDEF";
19
+ static const char *digit(int val)
20
+ {
21
+ static const char *bank = "0123456789ABCDEF";
30
22
  return bank + val;
31
23
  }
32
24
 
@@ -44,122 +36,126 @@ class String: public string
44
36
 
45
37
  static string dtoas(double val, int decimalPlaces) {
46
38
  double r = 0.5 * pow(0.1, decimalPlaces); // make sure that integer truncation will properly round
47
- if (::isnan(val)) return "nan";
48
- if (::isinf(val)) return "inf";
39
+ if (std::isnan(val)) return "nan";
40
+ if (std::isinf(val)) return "inf";
49
41
  val += val > 0 ? r : -r;
50
42
  if (val > 4294967040.0) return "ovf";
51
43
  if (val <-4294967040.0) return "ovf";
52
44
  return mytoas(val, 10) + "." + mytoa(abs(val - (long)val) * pow(10, decimalPlaces), 10);
53
45
  }
54
46
 
55
- public:
56
- ~String(void) {}
57
- String(const __FlashStringHelper *str): string((const char *)str) {}
58
- String(const char *cstr = ""): string(cstr) {}
59
- String(const string &str): string(str) {}
60
- String(const String &str): string(str) {}
61
- explicit String(char c): string(1, c) {}
62
-
63
- explicit String(unsigned char val, unsigned char base=10): string(mytoa(val, base)) {}
64
- explicit String(int val, unsigned char base=10): string(mytoas(val, base)) {}
65
- explicit String(unsigned int val , unsigned char base=10): string(mytoa(val, base)) {}
66
- explicit String(long val, unsigned char base=10): string(mytoas(val, base)) {}
67
- explicit String(unsigned long val, unsigned char base=10): string(mytoa(val, base)) {}
68
-
69
- explicit String(float val, unsigned char decimalPlaces=2): string(dtoas(val, decimalPlaces)) {}
70
- explicit String(double val, unsigned char decimalPlaces=2): string(dtoas(val, decimalPlaces)) {}
71
-
72
- String & operator = (const String &rhs) { assign(rhs); return *this; }
73
- String & operator = (const string &rhs) { assign(rhs); return *this; }
74
- String & operator = (const char *cstr) { assign(cstr); return *this; }
75
- String & operator = (const char c) { assign(1, c); return *this; }
76
-
77
- unsigned char concat(const __FlashStringHelper *str) { append((const char *)str); return 1; }
78
- unsigned char concat(const String &str) { append(str); return 1; }
79
- unsigned char concat(const char *cstr) { append(cstr); return 1; }
80
- unsigned char concat(char c) { append(1, c); return 1; }
81
- unsigned char concat(unsigned char c) { append(1, c); return 1; }
82
- unsigned char concat(int num) { append(String(num)); return 1; }
83
- unsigned char concat(unsigned int num) { append(String(num)); return 1; }
84
- unsigned char concat(long num) { append(String(num)); return 1; }
85
- unsigned char concat(unsigned long num) { append(String(num)); return 1; }
86
- unsigned char concat(float num) { append(String(num)); return 1; }
87
- unsigned char concat(double num) { append(String(num)); return 1; }
88
-
89
- String & operator += (const __FlashStringHelper *rhs) { concat(rhs); return *this; }
90
- String & operator += (const String &rhs) { concat(rhs); return *this; }
91
- String & operator += (const char *cstr) { concat(cstr); return *this; }
92
- String & operator += (char c) { concat(c); return *this; }
93
- String & operator += (unsigned char num) { concat(num); return *this; }
94
- String & operator += (int num) { concat(num); return *this; }
95
- String & operator += (unsigned int num) { concat(num); return *this; }
96
- String & operator += (long num) { concat(num); return *this; }
97
- String & operator += (unsigned long num) { concat(num); return *this; }
98
- String & operator += (float num) { concat(num); return *this; }
99
- String & operator += (double num) { concat(num); return *this; }
100
-
101
-
102
- int compareTo(const String &s) const { return compare(s); }
103
- unsigned char equals(const String &s) const { return compareTo(s) == 0; }
104
- unsigned char equals(const char *cstr) const { return compareTo(String(cstr)) == 0; }
105
- unsigned char equal(const String &s) const { return equals(s); }
106
- unsigned char equal(const char *cstr) const { return equals(cstr); }
107
- unsigned char equalsIgnoreCase(const String &s) const {
108
- String a = String(*this);
109
- String b = String(s);
110
- a.toUpperCase();
111
- b.toUpperCase();
112
- return a.compare(b) == 0;
113
- }
114
-
115
- unsigned char startsWith(const String &prefix) const { return find(prefix) == 0; }
116
- unsigned char startsWith(const String &prefix, unsigned int offset) const { return find(prefix, offset) == offset; }
117
- unsigned char endsWith(const String &suffix) const { return rfind(suffix) == length() - suffix.length(); }
118
-
119
- char charAt(unsigned int index) const { return operator[](index); }
120
- void setCharAt(unsigned int index, char c) { (*this)[index] = c; }
121
-
122
- void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const { copy((char*)buf, bufsize, index); }
123
- void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
124
- { getBytes((unsigned char *)buf, bufsize, index); }
125
-
126
- int indexOf( char ch ) const { return find(ch); }
127
- int indexOf( char ch, unsigned int fromIndex ) const { return find(ch, fromIndex); }
128
- int indexOf( const String &str ) const { return find(str); }
129
- int indexOf( const String &str, unsigned int fromIndex ) const { return find(str, fromIndex); }
130
- int lastIndexOf( char ch ) const { return rfind(ch); }
131
- int lastIndexOf( char ch, unsigned int fromIndex ) const { return rfind(ch, fromIndex); }
132
- int lastIndexOf( const String &str ) const { return rfind(str); }
133
- int lastIndexOf( const String &str, unsigned int fromIndex ) const { return rfind(str, fromIndex); }
134
- String substring( unsigned int beginIndex ) const { return String(substr(beginIndex)); }
135
- String substring( unsigned int beginIndex, unsigned int endIndex ) const { return String(substr(beginIndex, endIndex)); }
136
-
137
- void replace(const String& target, const String& repl) {
138
- int i = 0;
139
- while ((i = find(target, i)) != npos) {
140
- assign(substr(0, i) + repl + substr(i + target.length()));
141
- i += repl.length();
47
+ public:
48
+ ~String(void) {}
49
+ String(const __FlashStringHelper *str): string((const char *)str) {}
50
+ String(const char *cstr = ""): string(cstr) {}
51
+ String(const string &str): string(str) {}
52
+ String(const String &str): string(str) {}
53
+ explicit String(char c): string(1, c) {}
54
+
55
+ explicit String(unsigned char val, unsigned char base=10): string(mytoa(val, base)) {}
56
+ explicit String(int val, unsigned char base=10): string(mytoas(val, base)) {}
57
+ explicit String(unsigned int val , unsigned char base=10): string(mytoa(val, base)) {}
58
+ explicit String(long val, unsigned char base=10): string(mytoas(val, base)) {}
59
+ explicit String(unsigned long val, unsigned char base=10): string(mytoa(val, base)) {}
60
+
61
+ explicit String(float val, unsigned char decimalPlaces=2): string(dtoas(val, decimalPlaces)) {}
62
+ explicit String(double val, unsigned char decimalPlaces=2): string(dtoas(val, decimalPlaces)) {}
63
+
64
+ operator bool() const {
65
+ return true;
66
+ }
67
+
68
+ String & operator = (const String &rhs) { assign(rhs); return *this; }
69
+ String & operator = (const string &rhs) { assign(rhs); return *this; }
70
+ String & operator = (const char *cstr) { assign(cstr); return *this; }
71
+ String & operator = (const char c) { assign(1, c); return *this; }
72
+
73
+ unsigned char concat(const __FlashStringHelper *str) { append((const char *)str); return 1; }
74
+ unsigned char concat(const String &str) { append(str); return 1; }
75
+ unsigned char concat(const char *cstr) { append(cstr); return 1; }
76
+ unsigned char concat(char c) { append(1, c); return 1; }
77
+ unsigned char concat(unsigned char c) { append(1, c); return 1; }
78
+ unsigned char concat(int num) { append(String(num)); return 1; }
79
+ unsigned char concat(unsigned int num) { append(String(num)); return 1; }
80
+ unsigned char concat(long num) { append(String(num)); return 1; }
81
+ unsigned char concat(unsigned long num) { append(String(num)); return 1; }
82
+ unsigned char concat(float num) { append(String(num)); return 1; }
83
+ unsigned char concat(double num) { append(String(num)); return 1; }
84
+
85
+ String & operator += (const __FlashStringHelper *rhs) { concat(rhs); return *this; }
86
+ String & operator += (const String &rhs) { concat(rhs); return *this; }
87
+ String & operator += (const char *cstr) { concat(cstr); return *this; }
88
+ String & operator += (char c) { concat(c); return *this; }
89
+ String & operator += (unsigned char num) { concat(num); return *this; }
90
+ String & operator += (int num) { concat(num); return *this; }
91
+ String & operator += (unsigned int num) { concat(num); return *this; }
92
+ String & operator += (long num) { concat(num); return *this; }
93
+ String & operator += (unsigned long num) { concat(num); return *this; }
94
+ String & operator += (float num) { concat(num); return *this; }
95
+ String & operator += (double num) { concat(num); return *this; }
96
+
97
+
98
+ int compareTo(const String &s) const { return compare(s); }
99
+ unsigned char equals(const String &s) const { return compareTo(s) == 0; }
100
+ unsigned char equals(const char *cstr) const { return compareTo(String(cstr)) == 0; }
101
+ unsigned char equal(const String &s) const { return equals(s); }
102
+ unsigned char equal(const char *cstr) const { return equals(cstr); }
103
+ unsigned char equalsIgnoreCase(const String &s) const {
104
+ String a = String(*this);
105
+ String b = String(s);
106
+ a.toUpperCase();
107
+ b.toUpperCase();
108
+ return a.compare(b) == 0;
142
109
  }
143
- }
144
- void replace(char target, char repl) {
145
- replace(String(target), String(repl));
146
- }
147
- void remove(unsigned int index) { assign(substr(0, index)); }
148
- void remove(unsigned int index, unsigned int count) { assign(substr(0, index) + substr(min(length(), index + count), count)); }
149
- void toLowerCase(void) { std::transform(begin(), end(), begin(), ::tolower); }
150
- void toUpperCase(void) { std::transform(begin(), end(), begin(), ::toupper); }
151
-
152
- void trim(void) {
153
- int b;
154
- int e;
155
- for (b = 0; b < length() && isSpace(charAt(b)); ++b);
156
- for (e = length() - 1; e > b && isSpace(charAt(e)); --e);
157
- assign(substr(b, e - b + 1));
158
- }
159
-
160
- long toInt(void) const { return std::stol(*this); }
161
- float toFloat(void) const { return std::stof(*this); }
162
- double toDouble(void) const { return std::stod(*this); }
110
+
111
+ unsigned char startsWith(const String &prefix) const { return find(prefix) == 0; }
112
+ unsigned char startsWith(const String &prefix, unsigned int offset) const { return find(prefix, offset) == offset; }
113
+ unsigned char endsWith(const String &suffix) const { return rfind(suffix) == length() - suffix.length(); }
114
+
115
+ char charAt(unsigned int index) const { return operator[](index); }
116
+ void setCharAt(unsigned int index, char c) { (*this)[index] = c; }
117
+
118
+ void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const { copy((char*)buf, bufsize, index); }
119
+ void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
120
+ { getBytes((unsigned char *)buf, bufsize, index); }
121
+
122
+ int indexOf( char ch ) const { return find(ch); }
123
+ int indexOf( char ch, unsigned int fromIndex ) const { return find(ch, fromIndex); }
124
+ int indexOf( const String &str ) const { return find(str); }
125
+ int indexOf( const String &str, unsigned int fromIndex ) const { return find(str, fromIndex); }
126
+ int lastIndexOf( char ch ) const { return rfind(ch); }
127
+ int lastIndexOf( char ch, unsigned int fromIndex ) const { return rfind(ch, fromIndex); }
128
+ int lastIndexOf( const String &str ) const { return rfind(str); }
129
+ int lastIndexOf( const String &str, unsigned int fromIndex ) const { return rfind(str, fromIndex); }
130
+ String substring( unsigned int beginIndex ) const { return String(substr(beginIndex)); }
131
+ String substring( unsigned int beginIndex, unsigned int endIndex ) const { return String(substr(beginIndex, endIndex)); }
132
+
133
+ void replace(const String& target, const String& repl) {
134
+ int i = 0;
135
+ while ((i = find(target, i)) != npos) {
136
+ assign(substr(0, i) + repl + substr(i + target.length()));
137
+ i += repl.length();
138
+ }
139
+ }
140
+ void replace(char target, char repl) {
141
+ replace(String(target), String(repl));
142
+ }
143
+ void remove(unsigned int index) { assign(substr(0, index)); }
144
+ void remove(unsigned int index, unsigned int count) { assign(substr(0, index) + substr(min(length(), index + count), count)); }
145
+ void toLowerCase(void) { std::transform(begin(), end(), begin(), ::tolower); }
146
+ void toUpperCase(void) { std::transform(begin(), end(), begin(), ::toupper); }
147
+
148
+ void trim(void) {
149
+ int b;
150
+ int e;
151
+ for (b = 0; b < length() && isSpace(charAt(b)); ++b);
152
+ for (e = length() - 1; e > b && isSpace(charAt(e)); --e);
153
+ assign(substr(b, e - b + 1));
154
+ }
155
+
156
+ long toInt(void) const { return std::stol(*this); }
157
+ float toFloat(void) const { return std::stof(*this); }
158
+ double toDouble(void) const { return std::stod(*this); }
163
159
 
164
160
  };
165
161