diff mbox

[U-Boot,v4,04/13] Add isblank

Message ID 1314133621-6488-5-git-send-email-jason.hobbs@calxeda.com
State Accepted
Commit 93337abbfe2951c63a4e7b450da1848c6c69217f
Headers show

Commit Message

Jason Hobbs Aug. 23, 2011, 9:06 p.m. UTC
Existing ctype checks are implemented using a 256 byte lookup table,
allowing each character to be in any of 8 character classes. Since there
are 8 existing character classes without the blank class, I implemented
isblank without using the lookup table.  Since there are only two blank
characters - tab and space - this is a more reasonable approach than
doubling the size of the lookup table to accommodate one more class.

Signed-off-by: Jason Hobbs <jason.hobbs@calxeda.com>
---
new in v4

 include/linux/ctype.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

Comments

Mike Frysinger Aug. 23, 2011, 9:40 p.m. UTC | #1
On Tuesday, August 23, 2011 17:06:52 Jason Hobbs wrote:
> Existing ctype checks are implemented using a 256 byte lookup table,
> allowing each character to be in any of 8 character classes. Since there
> are 8 existing character classes without the blank class, I implemented
> isblank without using the lookup table.  Since there are only two blank
> characters - tab and space - this is a more reasonable approach than
> doubling the size of the lookup table to accommodate one more class.

and isspace() doesnt work because ... ?
-mike
Jason Hobbs Aug. 24, 2011, 3:40 p.m. UTC | #2
On Tue, Aug 23, 2011 at 05:40:35PM -0400, Mike Frysinger wrote:
> On Tuesday, August 23, 2011 17:06:52 Jason Hobbs wrote:
> > Existing ctype checks are implemented using a 256 byte lookup table,
> > allowing each character to be in any of 8 character classes. Since there
> > are 8 existing character classes without the blank class, I implemented
> > isblank without using the lookup table.  Since there are only two blank
> > characters - tab and space - this is a more reasonable approach than
> > doubling the size of the lookup table to accommodate one more class.
> 
> and isspace() doesnt work because ... ?

Because isspace matches characters other than tab and space, like end of
line, which isn't always desired.

Jason
diff mbox

Patch

diff --git a/include/linux/ctype.h b/include/linux/ctype.h
index 6dec944..42f9305 100644
--- a/include/linux/ctype.h
+++ b/include/linux/ctype.h
@@ -31,6 +31,12 @@  extern const unsigned char _ctype[];
 #define isupper(c)	((__ismask(c)&(_U)) != 0)
 #define isxdigit(c)	((__ismask(c)&(_D|_X)) != 0)
 
+/*
+ * Rather than doubling the size of the _ctype lookup table to hold a 'blank'
+ * flag, just check for space or tab.
+ */
+#define isblank(c)	(c == ' ' || c == '\t')
+
 #define isascii(c) (((unsigned char)(c))<=0x7f)
 #define toascii(c) (((unsigned char)(c))&0x7f)