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

Commita010db7

Browse files
committed
Bool as return value for logical operations
1 parente2d2f20 commita010db7

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
@@ -166,25 +166,25 @@ void String::invalidate(void)
166166
capacity = len =0;
167167
}
168168

169-
unsignedcharString::reserve(unsignedint size)
169+
boolString::reserve(unsignedint size)
170170
{
171171
if (buffer && capacity >= size)return1;
172172
if (changeBuffer(size)) {
173173
if (len ==0) buffer[0] =0;
174-
return1;
174+
returntrue;
175175
}
176-
return0;
176+
returnfalse;
177177
}
178178

179-
unsignedcharString::changeBuffer(unsignedint maxStrLen)
179+
boolString::changeBuffer(unsignedint maxStrLen)
180180
{
181181
char *newbuffer = (char *)realloc(buffer, maxStrLen +1);
182182
if (newbuffer) {
183183
buffer = newbuffer;
184184
capacity = maxStrLen;
185-
return1;
185+
returntrue;
186186
}
187-
return0;
187+
returnfalse;
188188
}
189189

190190
/*********************************************/
@@ -281,93 +281,93 @@ String & String::operator = (const __FlashStringHelper *pstr)
281281
/* concat*/
282282
/*********************************************/
283283

284-
unsignedcharString::concat(const String &s)
284+
boolString::concat(const String &s)
285285
{
286286
returnconcat(s.buffer, s.len);
287287
}
288288

289-
unsignedcharString::concat(constchar *cstr,unsignedint length)
289+
boolString::concat(constchar *cstr,unsignedint length)
290290
{
291291
unsignedint newlen = len + length;
292-
if (!cstr)return0;
293-
if (length ==0)return1;
294-
if (!reserve(newlen))return0;
292+
if (!cstr)returnfalse;
293+
if (length ==0)returntrue;
294+
if (!reserve(newlen))returnfalse;
295295
memcpy(buffer + len, cstr, length);
296296
len = newlen;
297297
buffer[len] ='\0';
298-
return1;
298+
returntrue;
299299
}
300300

301-
unsignedcharString::concat(constchar *cstr)
301+
boolString::concat(constchar *cstr)
302302
{
303-
if (!cstr)return0;
303+
if (!cstr)returnfalse;
304304
returnconcat(cstr,strlen(cstr));
305305
}
306306

307-
unsignedcharString::concat(char c)
307+
boolString::concat(char c)
308308
{
309309
returnconcat(&c,1);
310310
}
311311

312-
unsignedcharString::concat(unsignedchar num)
312+
boolString::concat(unsignedchar num)
313313
{
314314
char buf[1 +3 *sizeof(unsignedchar)];
315315
itoa(num, buf,10);
316316
returnconcat(buf);
317317
}
318318

319-
unsignedcharString::concat(int num)
319+
boolString::concat(int num)
320320
{
321321
char buf[2 +3 *sizeof(int)];
322322
itoa(num, buf,10);
323323
returnconcat(buf);
324324
}
325325

326-
unsignedcharString::concat(unsignedint num)
326+
boolString::concat(unsignedint num)
327327
{
328328
char buf[1 +3 *sizeof(unsignedint)];
329329
utoa(num, buf,10);
330330
returnconcat(buf);
331331
}
332332

333-
unsignedcharString::concat(long num)
333+
boolString::concat(long num)
334334
{
335335
char buf[2 +3 *sizeof(long)];
336336
ltoa(num, buf,10);
337337
returnconcat(buf);
338338
}
339339

340-
unsignedcharString::concat(unsignedlong num)
340+
boolString::concat(unsignedlong num)
341341
{
342342
char buf[1 +3 *sizeof(unsignedlong)];
343343
ultoa(num, buf,10);
344344
returnconcat(buf);
345345
}
346346

347-
unsignedcharString::concat(float num)
347+
boolString::concat(float num)
348348
{
349349
char buf[20];
350350
char* string =dtostrf(num,4,2, buf);
351351
returnconcat(string);
352352
}
353353

354-
unsignedcharString::concat(double num)
354+
boolString::concat(double num)
355355
{
356356
char buf[20];
357357
char* string =dtostrf(num,4,2, buf);
358358
returnconcat(string);
359359
}
360360

361-
unsignedcharString::concat(const __FlashStringHelper * str)
361+
boolString::concat(const __FlashStringHelper * str)
362362
{
363-
if (!str)return0;
363+
if (!str)returnfalse;
364364
int length =strlen_P((constchar *) str);
365-
if (length ==0)return1;
365+
if (length ==0)returntrue;
366366
unsignedint newlen = len + length;
367-
if (!reserve(newlen))return0;
367+
if (!reserve(newlen))returnfalse;
368368
strcpy_P(buffer + len, (constchar *) str);
369369
len = newlen;
370-
return1;
370+
returntrue;
371371
}
372372

373373
/*********************************************/
@@ -475,46 +475,46 @@ int String::compareTo(const char *cstr) const
475475
returnstrcmp(buffer, cstr);
476476
}
477477

478-
unsignedcharString::equals(const String &s2)const
478+
boolString::equals(const String &s2)const
479479
{
480480
return (len == s2.len &&compareTo(s2) ==0);
481481
}
482482

483-
unsignedcharString::equals(constchar *cstr)const
483+
boolString::equals(constchar *cstr)const
484484
{
485485
if (len ==0)return (cstr ==NULL || *cstr ==0);
486486
if (cstr ==NULL)return buffer[0] ==0;
487487
returnstrcmp(buffer, cstr) ==0;
488488
}
489489

490-
unsignedcharString::equalsIgnoreCase(const String &s2 )const
490+
boolString::equalsIgnoreCase(const String &s2 )const
491491
{
492-
if (this == &s2)return1;
493-
if (len != s2.len)return0;
494-
if (len ==0)return1;
492+
if (this == &s2)returntrue;
493+
if (len != s2.len)returnfalse;
494+
if (len ==0)returntrue;
495495
constchar *p1 = buffer;
496496
constchar *p2 = s2.buffer;
497497
while (*p1) {
498-
if (tolower(*p1++) !=tolower(*p2++))return0;
498+
if (tolower(*p1++) !=tolower(*p2++))returnfalse;
499499
}
500-
return1;
500+
returntrue;
501501
}
502502

503-
unsignedcharString::startsWith(const String &s2 )const
503+
boolString::startsWith(const String &s2 )const
504504
{
505-
if (len < s2.len)return0;
505+
if (len < s2.len)returnfalse;
506506
returnstartsWith(s2,0);
507507
}
508508

509-
unsignedcharString::startsWith(const String &s2,unsignedint offset )const
509+
boolString::startsWith(const String &s2,unsignedint offset )const
510510
{
511-
if (offset > len - s2.len || !buffer || !s2.buffer)return0;
511+
if (offset > len - s2.len || !buffer || !s2.buffer)returnfalse;
512512
returnstrncmp( &buffer[offset], s2.buffer, s2.len ) ==0;
513513
}
514514

515-
unsignedcharString::endsWith(const String &s2 )const
515+
boolString::endsWith(const String &s2 )const
516516
{
517-
if ( len < s2.len || !buffer || !s2.buffer)return0;
517+
if ( len < s2.len || !buffer || !s2.buffer)returnfalse;
518518
returnstrcmp(&buffer[len - s2.len], s2.buffer) ==0;
519519
}
520520

‎api/String.h

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

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

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

184184
// character acccess
185185
charcharAt(unsignedint index)const;
@@ -228,7 +228,7 @@ class String
228228
protected:
229229
voidinit(void);
230230
voidinvalidate(void);
231-
unsignedcharchangeBuffer(unsignedint maxStrLen);
231+
boolchangeBuffer(unsignedint maxStrLen);
232232

233233
// copy and move
234234
String &copy(constchar *cstr,unsignedint length);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp