This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed
tests/ServiceStack.Text.Tests Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -601,11 +601,9 @@ public static string ToLowercaseUnderscore(this string value)
601
601
return sb . ToString ( ) ;
602
602
}
603
603
604
- public static string SafeSubstring ( this string value , int length )
604
+ public static string SafeSubstring ( this string value , int startIndex )
605
605
{
606
- return String . IsNullOrEmpty ( value )
607
- ? String . Empty
608
- : value . Substring ( Math . Min ( length , value . Length ) ) ;
606
+ return SafeSubstring ( value , startIndex , value . Length ) ;
609
607
}
610
608
611
609
public static string SafeSubstring ( this string value , int startIndex , int length )
Original file line number Diff line number Diff line change @@ -226,5 +226,26 @@ public void Can_ParseKeyValueText()
226
226
Assert . That ( "a:b\n c:d" . ParseKeyValueText ( ) [ "c" ] , Is . EqualTo ( "d" ) ) ;
227
227
Assert . That ( "a:b\r \n c:d" . ParseKeyValueText ( ) [ "c" ] , Is . EqualTo ( "d" ) ) ;
228
228
}
229
+
230
+ [ Test ]
231
+ public void Can_SafeSubstring_with_no_length {
232
+
233
+ var input = "TestString" ;
234
+ Assert . That ( input . SafeSubstring( 0 ) , Is . EqualTo( "TestString") ) ;
235
+ Assert . That ( input . SafeSubstring( 2 ) , Is . EqualTo( "stString") ) ;
236
+ Assert . That ( input . SafeSubstring( 20 ) , Is . EqualTo( "") ) ;
237
+ }
238
+
239
+ [ Test ]
240
+ public void Can_SafeSubstring_with_length {
241
+ var input = "TestString" ;
242
+ Assert . That ( input . SafeSubstring( 0 , 4 ) , Is . EqualTo( "Test") ) ;
243
+ Assert . That ( input . SafeSubstring( 2 , 4 ) , Is . EqualTo( "stSt") ) ;
244
+ Assert . That ( input . SafeSubstring( 20 , 4 ) , Is . EqualTo( "") ) ;
245
+ Assert . That ( input . SafeSubstring( 0 , 20 ) , Is . EqualTo( "TestString") ) ;
246
+
247
+ }
248
+ }
249
+ }
229
250
}
230
- }
251
+ }
You can’t perform that action at this time.
0 commit comments