Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit438172b

Browse files
authored
Merge pull request#147 from mcspr/bools
Bool as return value for logical operations
2 parents42f8e11 +a010db7 commit438172b

File tree

2 files changed

+83
-83
lines changed

2 files changed

+83
-83
lines changed

‎api/String.cpp‎

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -165,25 +165,25 @@ void String::invalidate(void)
165165
capacity = len =0;
166166
}
167167

168-
unsignedcharString::reserve(unsignedint size)
168+
boolString::reserve(unsignedint size)
169169
{
170170
if (buffer && capacity >= size)return1;
171171
if (changeBuffer(size)) {
172172
if (len ==0) buffer[0] =0;
173-
return1;
173+
returntrue;
174174
}
175-
return0;
175+
returnfalse;
176176
}
177177

178-
unsignedcharString::changeBuffer(unsignedint maxStrLen)
178+
boolString::changeBuffer(unsignedint maxStrLen)
179179
{
180180
char *newbuffer = (char *)realloc(buffer, maxStrLen +1);
181181
if (newbuffer) {
182182
buffer = newbuffer;
183183
capacity = maxStrLen;
184-
return1;
184+
returntrue;
185185
}
186-
return0;
186+
returnfalse;
187187
}
188188

189189
/*********************************************/
@@ -269,93 +269,93 @@ String & String::operator = (const __FlashStringHelper *pstr)
269269
/* concat*/
270270
/*********************************************/
271271

272-
unsignedcharString::concat(const String &s)
272+
boolString::concat(const String &s)
273273
{
274274
returnconcat(s.buffer, s.len);
275275
}
276276

277-
unsignedcharString::concat(constchar *cstr,unsignedint length)
277+
boolString::concat(constchar *cstr,unsignedint length)
278278
{
279279
unsignedint newlen = len + length;
280-
if (!cstr)return0;
281-
if (length ==0)return1;
282-
if (!reserve(newlen))return0;
280+
if (!cstr)returnfalse;
281+
if (length ==0)returntrue;
282+
if (!reserve(newlen))returnfalse;
283283
memcpy(buffer + len, cstr, length);
284284
len = newlen;
285285
buffer[len] ='\0';
286-
return1;
286+
returntrue;
287287
}
288288

289-
unsignedcharString::concat(constchar *cstr)
289+
boolString::concat(constchar *cstr)
290290
{
291-
if (!cstr)return0;
291+
if (!cstr)returnfalse;
292292
returnconcat(cstr,strlen(cstr));
293293
}
294294

295-
unsignedcharString::concat(char c)
295+
boolString::concat(char c)
296296
{
297297
returnconcat(&c,1);
298298
}
299299

300-
unsignedcharString::concat(unsignedchar num)
300+
boolString::concat(unsignedchar num)
301301
{
302302
char buf[1 +3 *sizeof(unsignedchar)];
303303
itoa(num, buf,10);
304304
returnconcat(buf);
305305
}
306306

307-
unsignedcharString::concat(int num)
307+
boolString::concat(int num)
308308
{
309309
char buf[2 +3 *sizeof(int)];
310310
itoa(num, buf,10);
311311
returnconcat(buf);
312312
}
313313

314-
unsignedcharString::concat(unsignedint num)
314+
boolString::concat(unsignedint num)
315315
{
316316
char buf[1 +3 *sizeof(unsignedint)];
317317
utoa(num, buf,10);
318318
returnconcat(buf);
319319
}
320320

321-
unsignedcharString::concat(long num)
321+
boolString::concat(long num)
322322
{
323323
char buf[2 +3 *sizeof(long)];
324324
ltoa(num, buf,10);
325325
returnconcat(buf);
326326
}
327327

328-
unsignedcharString::concat(unsignedlong num)
328+
boolString::concat(unsignedlong num)
329329
{
330330
char buf[1 +3 *sizeof(unsignedlong)];
331331
ultoa(num, buf,10);
332332
returnconcat(buf);
333333
}
334334

335-
unsignedcharString::concat(float num)
335+
boolString::concat(float num)
336336
{
337337
char buf[20];
338338
char* string =dtostrf(num,4,2, buf);
339339
returnconcat(string);
340340
}
341341

342-
unsignedcharString::concat(double num)
342+
boolString::concat(double num)
343343
{
344344
char buf[20];
345345
char* string =dtostrf(num,4,2, buf);
346346
returnconcat(string);
347347
}
348348

349-
unsignedcharString::concat(const __FlashStringHelper * str)
349+
boolString::concat(const __FlashStringHelper * str)
350350
{
351-
if (!str)return0;
351+
if (!str)returnfalse;
352352
int length =strlen_P((constchar *) str);
353-
if (length ==0)return1;
353+
if (length ==0)returntrue;
354354
unsignedint newlen = len + length;
355-
if (!reserve(newlen))return0;
355+
if (!reserve(newlen))returnfalse;
356356
strcpy_P(buffer + len, (constchar *) str);
357357
len = newlen;
358-
return1;
358+
returntrue;
359359
}
360360

361361
/*********************************************/
@@ -463,46 +463,46 @@ int String::compareTo(const char *cstr) const
463463
returnstrcmp(buffer, cstr);
464464
}
465465

466-
unsignedcharString::equals(const String &s2)const
466+
boolString::equals(const String &s2)const
467467
{
468468
return (len == s2.len &&compareTo(s2) ==0);
469469
}
470470

471-
unsignedcharString::equals(constchar *cstr)const
471+
boolString::equals(constchar *cstr)const
472472
{
473473
if (len ==0)return (cstr ==NULL || *cstr ==0);
474474
if (cstr ==NULL)return buffer[0] ==0;
475475
returnstrcmp(buffer, cstr) ==0;
476476
}
477477

478-
unsignedcharString::equalsIgnoreCase(const String &s2 )const
478+
boolString::equalsIgnoreCase(const String &s2 )const
479479
{
480-
if (this == &s2)return1;
481-
if (len != s2.len)return0;
482-
if (len ==0)return1;
480+
if (this == &s2)returntrue;
481+
if (len != s2.len)returnfalse;
482+
if (len ==0)returntrue;
483483
constchar *p1 = buffer;
484484
constchar *p2 = s2.buffer;
485485
while (*p1) {
486-
if (tolower(*p1++) !=tolower(*p2++))return0;
486+
if (tolower(*p1++) !=tolower(*p2++))returnfalse;
487487
}
488-
return1;
488+
returntrue;
489489
}
490490

491-
unsignedcharString::startsWith(const String &s2 )const
491+
boolString::startsWith(const String &s2 )const
492492
{
493-
if (len < s2.len)return0;
493+
if (len < s2.len)returnfalse;
494494
returnstartsWith(s2,0);
495495
}
496496

497-
unsignedcharString::startsWith(const String &s2,unsignedint offset )const
497+
boolString::startsWith(const String &s2,unsignedint offset )const
498498
{
499-
if (offset > len - s2.len || !buffer || !s2.buffer)return0;
499+
if (offset > len - s2.len || !buffer || !s2.buffer)returnfalse;
500500
returnstrncmp( &buffer[offset], s2.buffer, s2.len ) ==0;
501501
}
502502

503-
unsignedcharString::endsWith(const String &s2 )const
503+
boolString::endsWith(const String &s2 )const
504504
{
505-
if ( len < s2.len || !buffer || !s2.buffer)return0;
505+
if ( len < s2.len || !buffer || !s2.buffer)returnfalse;
506506
returnstrcmp(&buffer[len - s2.len], s2.buffer) ==0;
507507
}
508508

‎api/String.h‎

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class String
8989
// return true on success, false on failure (in which case, the string
9090
// is left unchanged). reserve(0), if successful, will validate an
9191
// invalid string (i.e., "if (s)" will be true afterwards)
92-
unsignedcharreserve(unsignedint size);
92+
boolreserve(unsignedint size);
9393
inlineunsignedintlength(void)const {return len;}
9494

9595
// creates a copy of the assigned value. if the value is null or
@@ -107,19 +107,19 @@ class String
107107
// returns true on success, false on failure (in which case, the string
108108
// is left unchanged). if the argument is null or invalid, the
109109
// concatenation is considered unsucessful.
110-
unsignedcharconcat(const String &str);
111-
unsignedcharconcat(constchar *cstr);
112-
unsignedcharconcat(constchar *cstr,unsignedint length);
113-
unsignedcharconcat(constuint8_t *cstr,unsignedint length) {returnconcat((constchar*)cstr, length);}
114-
unsignedcharconcat(char c);
115-
unsignedcharconcat(unsignedchar num);
116-
unsignedcharconcat(int num);
117-
unsignedcharconcat(unsignedint num);
118-
unsignedcharconcat(long num);
119-
unsignedcharconcat(unsignedlong num);
120-
unsignedcharconcat(float num);
121-
unsignedcharconcat(double num);
122-
unsignedcharconcat(const __FlashStringHelper * str);
110+
boolconcat(const String &str);
111+
boolconcat(constchar *cstr);
112+
boolconcat(constchar *cstr,unsignedint length);
113+
boolconcat(constuint8_t *cstr,unsignedint length) {returnconcat((constchar*)cstr, length);}
114+
boolconcat(char c);
115+
boolconcat(unsignedchar num);
116+
boolconcat(int num);
117+
boolconcat(unsignedint num);
118+
boolconcat(long num);
119+
boolconcat(unsignedlong num);
120+
boolconcat(float num);
121+
boolconcat(double num);
122+
boolconcat(const __FlashStringHelper * str);
123123

124124
// if there's not enough memory for the concatenated value, the string
125125
// will be left unchanged (but this isn't signalled in any way)
@@ -151,33 +151,33 @@ class String
151151
operatorStringIfHelperType()const {return buffer ? &String::StringIfHelper :0; }
152152
intcompareTo(const String &s)const;
153153
intcompareTo(constchar *cstr)const;
154-
unsignedcharequals(const String &s)const;
155-
unsignedcharequals(constchar *cstr)const;
156-
157-
friendunsignedcharoperator == (const String &a,const String &b) {return a.equals(b); }
158-
friendunsignedcharoperator == (const String &a,constchar *b) {return a.equals(b); }
159-
friendunsignedcharoperator == (constchar *a,const String &b) {return b == a; }
160-
friendunsignedcharoperator < (const String &a,const String &b) {return a.compareTo(b) <0; }
161-
friendunsignedcharoperator < (const String &a,constchar *b) {return a.compareTo(b) <0; }
162-
friendunsignedcharoperator < (constchar *a,const String &b) {return b.compareTo(a) >0; }
163-
164-
friendunsignedcharoperator != (const String &a,const String &b) {return !(a == b); }
165-
friendunsignedcharoperator != (const String &a,constchar *b) {return !(a == b); }
166-
friendunsignedcharoperator != (constchar *a,const String &b) {return !(a == b); }
167-
friendunsignedcharoperator > (const String &a,const String &b) {return b < a; }
168-
friendunsignedcharoperator > (const String &a,constchar *b) {return b < a; }
169-
friendunsignedcharoperator > (constchar *a,const String &b) {return b < a; }
170-
friendunsignedcharoperator <= (const String &a,const String &b) {return !(b < a); }
171-
friendunsignedcharoperator <= (const String &a,constchar *b) {return !(b < a); }
172-
friendunsignedcharoperator <= (constchar *a,const String &b) {return !(b < a); }
173-
friendunsignedcharoperator >= (const String &a,const String &b) {return !(a < b); }
174-
friendunsignedcharoperator >= (const String &a,constchar *b) {return !(a < b); }
175-
friendunsignedcharoperator >= (constchar *a,const String &b) {return !(a < b); }
176-
177-
unsignedcharequalsIgnoreCase(const String &s)const;
178-
unsignedcharstartsWith(const String &prefix)const;
179-
unsignedcharstartsWith(const String &prefix,unsignedint offset)const;
180-
unsignedcharendsWith(const String &suffix)const;
154+
boolequals(const String &s)const;
155+
boolequals(constchar *cstr)const;
156+
157+
friendbooloperator == (const String &a,const String &b) {return a.equals(b); }
158+
friendbooloperator == (const String &a,constchar *b) {return a.equals(b); }
159+
friendbooloperator == (constchar *a,const String &b) {return b == a; }
160+
friendbooloperator < (const String &a,const String &b) {return a.compareTo(b) <0; }
161+
friendbooloperator < (const String &a,constchar *b) {return a.compareTo(b) <0; }
162+
friendbooloperator < (constchar *a,const String &b) {return b.compareTo(a) >0; }
163+
164+
friendbooloperator != (const String &a,const String &b) {return !(a == b); }
165+
friendbooloperator != (const String &a,constchar *b) {return !(a == b); }
166+
friendbooloperator != (constchar *a,const String &b) {return !(a == b); }
167+
friendbooloperator > (const String &a,const String &b) {return b < a; }
168+
friendbooloperator > (const String &a,constchar *b) {return b < a; }
169+
friendbooloperator > (constchar *a,const String &b) {return b < a; }
170+
friendbooloperator <= (const String &a,const String &b) {return !(b < a); }
171+
friendbooloperator <= (const String &a,constchar *b) {return !(b < a); }
172+
friendbooloperator <= (constchar *a,const String &b) {return !(b < a); }
173+
friendbooloperator >= (const String &a,const String &b) {return !(a < b); }
174+
friendbooloperator >= (const String &a,constchar *b) {return !(a < b); }
175+
friendbooloperator >= (constchar *a,const String &b) {return !(a < b); }
176+
177+
boolequalsIgnoreCase(const String &s)const;
178+
boolstartsWith(const String &prefix)const;
179+
boolstartsWith(const String &prefix,unsignedint offset)const;
180+
boolendsWith(const String &suffix)const;
181181

182182
// character acccess
183183
charcharAt(unsignedint index)const;
@@ -226,7 +226,7 @@ class String
226226
protected:
227227
voidinit(void);
228228
voidinvalidate(void);
229-
unsignedcharchangeBuffer(unsignedint maxStrLen);
229+
boolchangeBuffer(unsignedint maxStrLen);
230230

231231
// copy and move
232232
String &copy(constchar *cstr,unsignedint length);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp