Tip: #107 - Convert enum to string table
Created: September 5, 2001 0:01 Complexity: basic Author: Thomas Ramming Version: 5.7 Karma: 8/4 Imported from: Tip#107
When testing your own C/C++ programs you sometimes wish to have a trace output, which shows you, which enum value is used.
You can do this by creating a string table for that enum type, which contains the enum identifyer as a string.
e.g.
printf ("%s", MyEnumStringTable [ MyEnumVal] );
You can create the complete string table by:
- marking the lines containing the complete typedef enum
- selecting menu C/C++.transform enum2Stringtab
You can create string table entries by:
- marking the lines within the typedef enum
- selecting menu C/C++.transform enum2String
This makes it easy to keep the enum (on changes) consistent to the string table.
Add the following lines to your .gvimrc/_gvimrc file:
31amenu C/C++.transform\ enum2Stringtab :s#[ ]*\\(\\w\\+\\)#/* \\1 */ "\\1"#<CR>o};<ESC>u�Ostatic const char* const Names[] = {<ESC><CR>:noh<CR> 31vmenu C/C++.transform\ enum2Stringtab :s#[ ]*\\(\\w\\+\\)#/* \\1 */ "\\1"#<CR>o};<ESC>u�Ostatic const char* const Names[] = {<ESC><CR>:noh<CR> 31amenu C/C++.transform\ enum2String :s#[ ]*\\(\\w\\+\\)#/* \\1 */ "\\1"#<CR>o}<ESC>:noh<CR> 31vmenu C/C++.transform\ enum2String :s#[ ]*\\(\\w\\+\\)#/* \\1 */ "\\1"#<CR>o}<ESC>:noh<CR>