aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/string/enum.cpp
blob: 5f8c032edfe4639d9c7386ff0d81809911837948 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "enum.h"
 
#include "format.h"
 
namespace NYT { 
 
//////////////////////////////////////////////////////////////////////////////// 
 
TString DecodeEnumValue(TStringBuf value)
{ 
    auto camelValue = UnderscoreCaseToCamelCase(value); 
    auto underscoreValue = CamelCaseToUnderscoreCase(camelValue);
    if (value != underscoreValue) {
        throw TSimpleException(Format("Enum value %Qv is not in a proper underscore case; did you mean %Qv?", 
            value,
            underscoreValue)); 
    }
    return camelValue; 
} 
 
TString EncodeEnumValue(TStringBuf value)
{ 
    return CamelCaseToUnderscoreCase(value); 
} 
 
namespace NDetail { 
 
void ThrowMalformedEnumValueException(TStringBuf typeName, TStringBuf value) 
{
    throw TSimpleException(Format("Error parsing %v value %Qv", 
        typeName, 
        value)); 
}

void FormatUnknownEnumValue(TStringBuilderBase* builder, TStringBuf name, i64 value) 
{
    builder->AppendFormat("%v(%v)", name, value);
}

} // namespace NDetail 
 
//////////////////////////////////////////////////////////////////////////////// 
 
} // namespace NYT