Finite State Machine is a powerful tool for text processing. The theory of finite state machine is complicated, but in actual text processing applications,
You only need to understand the finite state machine model and understand the state transfer relationship to quickly write the program.
Such as parsing the network configuration file (similar to the format of the/etc/sysconfig/network-scripts/ifcfg-eth0 file)
The format is as follows: (the behavior comment line starts with #. Valid configuration characters include numbers, letters, and periods)
# This is a net work Config File
Ipaddr = 192.168.1.71
Netmask = 255.255.255.0
Gateway = 192.168.1.1
We can define four states:
1. Initial status
2. Key status. This status is displayed when the configuration key is read.
3. Value status. This status is displayed when the configuration value is read.
4. delim status, that is, the delimiter between key and Value
The status transition diagram is as follows: (for parsing configuration files such as XML and ini, the status transition diagram is much more complex)
The specific implementation is as follows: (c)
Parse_config.rar
Parse_ini.rar (INI file parser)