Skip to content

Commit fd2d850

Browse files
committed
fix: 小驼峰转蛇形错误
1 parent 9e8e02b commit fd2d850

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

OneBot-Interface/Core/Util/StringUtils.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ public static string ToSeparatedCase(string s, char separator, CaseType caseType
166166
{
167167
StringBuilder sb = new StringBuilder();
168168
char[] src = s.ToCharArray();
169-
170-
bool fstWord = true;
171-
for (int i = 0; i < src.Length; i++)
169+
170+
int t = 0;
171+
for (int i = 0; i < src.Length; i++, t++)
172172
{
173173
if (char.IsSeparator(src[i]))
174174
{
175175
sb.Append(src[i]);
176-
fstWord = true;
176+
t = -1;
177177
continue;
178178
}
179179
if (char.IsUpper(src[i]))
@@ -194,10 +194,8 @@ public static string ToSeparatedCase(string s, char separator, CaseType caseType
194194
}
195195
if (match)
196196
{
197-
if (!fstWord)
197+
if (t != 0)
198198
sb.Append(separator);
199-
else
200-
fstWord = false;
201199
for (int k = 0; k < word.Length; k++)
202200
{
203201
if (caseType == CaseType.Upper)
@@ -214,10 +212,8 @@ public static string ToSeparatedCase(string s, char separator, CaseType caseType
214212
if (skip)
215213
continue;
216214
}
217-
if (!fstWord)
215+
if (t != 0)
218216
sb.Append(separator);
219-
else
220-
fstWord = false;
221217
}
222218
if (caseType == CaseType.Upper)
223219
sb.Append(char.ToUpper(src[i]));

0 commit comments

Comments
 (0)