P
pozz
I have a string that is generated from a numerical keypad with decimal
numbers 0-9 and the two special characters * and #, similar to a phone
keypad.
I want to parse the string and make something or something else
depending on the current state and the string itself. Generally the
string can be:
#
*#
*<g>#
<c>*<g>#
<c>#
<c>*#
where
<c> is a 4- to 6-digits code
<g> is the exact digit '1', '2' or '3'.
Depending on the current state, some combinations are valid, others not.
In some cases the code should be valid (already saved in the system),
in other cases it could be new (when a new code must be entered to
change the current one).
I think I have solved the problem trying to split the string in to three
fields: <c>, '*' and <g>. If the first char is a digit, it must be a 4-
to 6- code, otherwise it must be a '*' or a '#', and so on...
Even if my code works, I don't think this is an elegant solution. What
happens if in the feature I decide to change one combination? For
example, from "#" to "###"? Or from "<c>*#" to "*<c>#"?
I have to recode everything, because my assumption the string can be
split in three fields in that order is not true anymore.
What is the best approach to implement a simple parser like this?
numbers 0-9 and the two special characters * and #, similar to a phone
keypad.
I want to parse the string and make something or something else
depending on the current state and the string itself. Generally the
string can be:
#
*#
*<g>#
<c>*<g>#
<c>#
<c>*#
where
<c> is a 4- to 6-digits code
<g> is the exact digit '1', '2' or '3'.
Depending on the current state, some combinations are valid, others not.
In some cases the code should be valid (already saved in the system),
in other cases it could be new (when a new code must be entered to
change the current one).
I think I have solved the problem trying to split the string in to three
fields: <c>, '*' and <g>. If the first char is a digit, it must be a 4-
to 6- code, otherwise it must be a '*' or a '#', and so on...
Even if my code works, I don't think this is an elegant solution. What
happens if in the feature I decide to change one combination? For
example, from "#" to "###"? Or from "<c>*#" to "*<c>#"?
I have to recode everything, because my assumption the string can be
split in three fields in that order is not true anymore.
What is the best approach to implement a simple parser like this?