editionFromString function
Parses an edition declaration or syntax string into its numeric value.
Accepts the file edition = "..." forms ("2023", "2024", "2026"), the
fully-qualified enum names ("EDITION_2023"), and the legacy syntax
strings ("proto2", "proto3"). Returns editionUnknown for anything
unrecognized (callers decide whether that is an error).
Implementation
int editionFromString(String s) {
switch (s) {
case 'proto2':
case 'EDITION_PROTO2':
return editionProto2;
case 'proto3':
case 'EDITION_PROTO3':
return editionProto3;
case '2023':
case 'EDITION_2023':
return edition2023;
case '2024':
case 'EDITION_2024':
return edition2024;
case '2026':
case 'EDITION_2026':
return edition2026;
case 'EDITION_LEGACY':
return editionLegacy;
default:
return editionUnknown;
}
}