1

I would like to get from lines such as this:

#define FACILITY_USERMODE_HYPERVISOR  53

to a line such as this, for use in an enum:

zFacilityUsermodeHypervisor = FACILITY_USERMODE_HYPERVISOR,

A quick regex replace does half the trick, is there a quick way to get the complete result?

Regex:   #define (FACILITY_\w+)\s+(\d+)
Replace: $1 = $1,

This leaves me with

FACILITY_USERMODE_HYPERVISOR = FACILITY_USERMODE_HYPERVISOR,

How would I convert the first part to CamelCase?

Felix Dombek
  • 13,664
  • 17
  • 79
  • 131

1 Answers1

1

This is definitely too difficult to achieve with VS S&R that does not support \l / \u and \L / \U ... \E operators in the replacement pattern.

I suggest acheiving it with 3 steps in Notepad++:

  • Duplicate the identifier you need to turn to CaMeL case with #define (FACILITY_\w+)(?=\s+\d+) regex (see demo). Your #define FACILITY_USERMODE_HYPERVISOR 53 will turn into #define FACILITY_USERMODE_HYPERVISOR %%% FACILITY_USERMODE_HYPERVISOR 53.
  • Apply the CaMeL case on the first occurrence of the identifier after #define with (?:#define\s+|(?!^)\G)\K_?([A-Za-z])([^\W_]*)_?(?=[\w\s]*%%%) regex and \u$1\L$2\E replacement. So, #define FACILITY_USERMODE_HYPERVISOR %%% FACILITY_USERMODE_HYPERVISOR 53 will turn into #define FacilityUsermodeHypervisor %%% FACILITY_USERMODE_HYPERVISOR 53.

enter image description here

  • The last step is just getting your desired output: removing what you do not need and adding the equal sign: use #define (Facility\w*)\s+%%%\s+(\w+)\s+\d+ regex with the z$1 = $2, replacement (see demo).
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563