@@ -231,7 +231,7 @@ struct PatternStringCase{
231
231
end
232
232
233
233
# Case tokens based on string case
234
- function _case ! (tokens, sc:: AbstractStringCase )
234
+ function case ! (tokens, sc:: AbstractStringCase )
235
235
# Case all token letters
236
236
tokens[begin : end ] = sc. tokencase .(tokens)
237
237
244
244
245
245
# Case first char of token if not empty, otherwise passthrough
246
246
function _casefirst (token:: AbstractString , case:: UpperLowerTitleAnyCase )
247
- if isempty (" " )
247
+ if isempty (token )
248
248
token
249
249
else
250
250
case (first (token)) * SubString (token, nextind (token, firstindex (token)))
@@ -260,12 +260,12 @@ function split(s::AbstractString, psc::PatternStringCase)
260
260
end
261
261
262
262
function join (tokens, dsc:: DelimiterStringCase )
263
- _case ! (tokens, dsc)
263
+ case ! (tokens, dsc)
264
264
return Base. join (tokens, dsc. dlm)
265
265
end
266
266
267
267
function join (tokens, psc:: PatternStringCase )
268
- _case ! (tokens, psc)
268
+ case ! (tokens, psc)
269
269
return Base. join (tokens)
270
270
end
271
271
@@ -277,11 +277,30 @@ function convert(
277
277
# Split string based on delimiter or pattern
278
278
tokens = split (s, input_sc)
279
279
280
+ # # Validate the input string on the input string case
281
+ # if s != join(tokens, input_sc)
282
+ # throw(
283
+ # DomainError(
284
+ # (s, input_sc),
285
+ # """
286
+ # convert called with a string that disobeys input StringCase.
287
+ # Either create a new StringCase that describes the input string
288
+ # and call convert with the new input StringCase
289
+ # or split the string into tokens yourself
290
+ # and call join(tokens, output_string_case)
291
+ # """,
292
+ # ),
293
+ # )
294
+ # end
295
+
280
296
# Join tokens based on delimiter or pattern
281
297
return join (tokens, output_sc)
282
298
end
283
299
284
300
function isvalid (s:: AbstractString , sc:: AbstractStringCase )
285
- # Validate converted string to the original string
286
- return s == convert (s, sc, sc)
301
+ # Split string based on delimiter or pattern
302
+ tokens = split (s, sc)
303
+
304
+ # Validate the input string on the input string case
305
+ return s == join (tokens, sc)
287
306
end
0 commit comments