Thread: Code Painter

  1. #31
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Minor detail:
    Code:
    !(pBuffer[i+k] == Keywords[j][k])
    would be easier to read as:
    Code:
    (pBuffer[i+k] != Keywords[j][k])
    (And it's shorter to write).

    Also, along the lines of what dwks says, there is a lot of code repetition in your functions still - particularly the bit that "take next character and output either itself or &gt/&lt. I think all of the loops can be translated into a generic function that loops around until some end condition - perhaps use strchr() to see if it's in a list of characters to terminate the current colour?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #32
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I was just reading through this thread quickly, and I noticed something that I thought I should comment on:
    Code:
    (ch == '<')? SS << "&lt;" : (ch == '>')? SS << "&gt;" : SS << ch;
    That might be easier to read as
    Code:
    SS << (ch == '<' ? "&lt;" : (ch == '>' ? "&gt;" : ch));
    I really don't like nesting the conditional operator, though, so I'd suggest using if/else or switch instead. Or, better yet, perhaps something like this:
    Code:
    const char *find = "<>";
    const char *replace[] = {"&lt;", "&gt;"};
    const char *p;
    
    if((p = strchr(find, ch))) SS << replace[p - find];
    else SS << ch;
    But maybe that's just overkill.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM