private static void parseValuePairs (String s, Event event) {
        int state = INITIAL;
        int i     = 0;
        int mark  = 0;
        String name = null;

        while (i < s.length()) {
            switch(s.charAt(i)) {

                case ' ':
                    if (state == IN_UNQUOTED) {
                        state = INITIAL;
                        event.setValue(name, s.substring(mark, i));
                    }

                    if (state == INITIAL) {
                        mark = -1;
                        break;
                    }

                    if (state == IN_QUOTED) {
                        break;
                    }

                    throw new IllegalStateException("space not allowed at " + i);

                case '=':
                    if (state == IN_NAME) {
                        name = s.substring(mark, i);
                        state = EQUALS;
                        break;
                    }
                    if (state == IN_QUOTED) {
                        break;
                    }

                    throw new IllegalStateException("'=' not allowed at " + i);

                case '"':
                    if (state == EQUALS) {
                        state = IN_QUOTED;
                        mark = i;
                        break;
                    }

                    if (state == IN_QUOTED) {
                        // skip escaped
                        if (s.charAt(i-1) == '\\') {
                            break;
                        }
                        event.setValue(name, s.substring(mark+1, i));
                        state = INITIAL;
                        break;
                    }

                    throw new IllegalStateException("'\"' not allowed at " + i);

                // ordinary characters
                default:
                    if (state == INITIAL) {
                        state = IN_NAME;
                        mark = i;
                        break;
                    }

                    if (state == EQUALS) {
                        state = IN_UNQUOTED;
                        mark = i;
                        break;
                    }
            }
            i++;
        }

        // mopping up.  when there is no more input to be processed
        // we need to take action if we are in one of the below states
        switch (state) {
            case IN_UNQUOTED:
                event.setValue(name, s.substring(mark, i));
                break;

            case IN_QUOTED:
                event.setValue(name, s.substring(mark+1, i));
                break;

            case IN_NAME:
                throw new IllegalStateException("ended in name");

            case EQUALS:
                event.setValue(name, null);
                break;
        }
    }
Okay, so I am good at making state machine based parsers,
but every time I do it it feels uncomfortable because it
isn't the sort of thing one ought to do by freehand :-).

<P>
Enjoy the graphic

<PRE>
   ___
   ',_`""\        .---,
      \   :~""``/`    |
       `;'     //`\   /
       /   __     |   ('.
      |_ ./O)\     \  `) \
     _/-.    `      `"`  |`-.
 .-=: `                  /   `-.
/o o \   ,_,           .        '.
L._._;_.-'           .            `'-.
  `'-.`             '                 `'-.
      `.         '                        `-._
        '-._. -'                              '.
           \                                    `\



</PRE>
vespalog/src/main/java/com/yahoo/log/event/Event.java