mNo edit summary |
(Added categories, clean up) |
||
Line 1: | Line 1: | ||
− | |||
{{review}} |
{{review}} |
||
{{Tip |
{{Tip |
||
Line 10: | Line 9: | ||
|rating=8/4 |
|rating=8/4 |
||
|text= |
|text= |
||
− | When testing your own C/C++ programs you sometimes wish to have a trace output, |
+ | When testing your own C/C++ programs you sometimes wish to have a trace output, which shows you, which enum value is used. |
⚫ | |||
− | which shows you, which enum value is used. |
||
− | |||
⚫ | |||
− | |||
− | which contains the enum identifyer as a string. |
||
e.g. |
e.g. |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
This makes it easy to keep the enum (on changes) consistent to the string table. |
This makes it easy to keep the enum (on changes) consistent to the string table. |
||
⚫ | |||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
+ | |||
− | |||
− | 31amenu C/C++.transform\ |
+ | 31amenu C/C++.transform\ enum2String :s#[ ]*\\(\\w\\+\\)#/* \\1 */ "\\1"#<CR>o}<ESC>:noh<CR> |
⚫ | |||
− | |||
⚫ | |||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | |||
− | |||
− | hint: '/sdfsdf' is added for deactivating search highlighting, |
||
− | |||
− | ok, you'll sure find a better way to do this. |
||
}} |
}} |
||
− | == Comments == |
||
− | You can use :noh to reset highlighting. |
||
− | |||
− | dion--AT--erebus.demon.nl |
||
− | , September 5, 2001 6:56 |
||
− | ---- |
||
<!-- parsed by vimtips.py in 0.264703 seconds--> |
<!-- parsed by vimtips.py in 0.264703 seconds--> |
||
+ | [[Category:C]] |
||
+ | [[Category:C plus plus]] |
Revision as of 10:45, 21 July 2007
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>