Skip to content

Commit 9d065a3

Browse files
JamesNKdeannagarcia
authored andcommitted
Refactor
1 parent b29af4e commit 9d065a3

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -187,35 +187,24 @@ private static void ValidateSymbolName(IDescriptor descriptor)
187187
throw new DescriptorValidationException(descriptor, "Missing name.");
188188
}
189189

190-
if (!IsValidSymbolNameFormat(descriptor.Name))
191-
{
192-
throw new DescriptorValidationException(descriptor,
193-
"\"" + descriptor.Name + "\" is not a valid identifier.");
194-
}
195-
}
196-
197-
/// <summary>
198-
/// Symbol name must start with a letter or underscore, and it can contain letters, numbers and underscores.
199-
/// </summary>
200-
private static bool IsValidSymbolNameFormat(string name)
201-
{
190+
// Symbol name must start with a letter or underscore, and it can contain letters, numbers and underscores.
191+
string name = descriptor.Name;
202192
if (!IsAsciiLetter(name[0]) && name[0] != '_')
203193
{
204-
return false;
194+
ThrowInvalidSymbolNameException(descriptor);
205195
}
206-
207196
for (int i = 1; i < name.Length; i++)
208197
{
209198
if (!IsAsciiLetter(name[i]) && !IsAsciiDigit(name[i]) && name[i] != '_')
210199
{
211-
return false;
200+
ThrowInvalidSymbolNameException(descriptor);
212201
}
213202
}
214203

215-
return true;
216-
217204
static bool IsAsciiLetter(char c) => (uint) ((c | 0x20) - 'a') <= 'z' - 'a';
218-
static bool IsAsciiDigit(char c) => (uint) (c - '0') <= ('9' - '0');
205+
static bool IsAsciiDigit(char c) => (uint) (c - '0') <= '9' - '0';
206+
static void ThrowInvalidSymbolNameException(IDescriptor descriptor) =>
207+
throw new DescriptorValidationException(descriptor, "\"" + descriptor.Name + "\" is not a valid identifier.");
219208
}
220209

221210
/// <summary>

0 commit comments

Comments
 (0)