litesoft
Diff Revisions
802
vs
803
for /trunk/Java/core/Anywhere/src/org/litesoft/core/typeutils/Strings.java
|
@@ -322,4 +322,85 @@ |
322 |
322 |
|
parts[count] = pStringToParse.substring( from ); |
323 |
323 |
|
return parts; |
324 |
324 |
|
} |
|
325 |
+ |
|
|
326 |
+ |
public static String replace( String pSource, char pToFind, String pToReplaceWith ) |
|
327 |
+ |
{ |
|
328 |
+ |
if ( (pSource != null) && (pToReplaceWith != null) ) |
|
329 |
+ |
{ |
|
330 |
+ |
int removeFor = 1; |
|
331 |
+ |
int adjustFromBy = pToReplaceWith.length(); |
|
332 |
+ |
int from = 0; |
|
333 |
+ |
for ( int at; -1 != (at = pSource.indexOf( pToFind, from )); from = at + adjustFromBy ) |
|
334 |
+ |
{ |
|
335 |
+ |
pSource = pSource.substring( 0, at ) + pToReplaceWith + pSource.substring( at + removeFor ); |
|
336 |
+ |
} |
|
337 |
+ |
} |
|
338 |
+ |
return pSource; |
|
339 |
+ |
} |
|
340 |
+ |
|
|
341 |
+ |
public static String replace( String pSource, String pToFind, String pToReplaceWith ) |
|
342 |
+ |
{ |
|
343 |
+ |
if ( (pSource != null) && (pToFind != null) && (pToReplaceWith != null) ) |
|
344 |
+ |
{ |
|
345 |
+ |
int removeFor = pToFind.length(); |
|
346 |
+ |
int adjustFromBy = pToReplaceWith.length(); |
|
347 |
+ |
int from = 0; |
|
348 |
+ |
for ( int at; -1 != (at = pSource.indexOf( pToFind, from )); from = at + adjustFromBy ) |
|
349 |
+ |
{ |
|
350 |
+ |
pSource = pSource.substring( 0, at ) + pToReplaceWith + pSource.substring( at + removeFor ); |
|
351 |
+ |
} |
|
352 |
+ |
} |
|
353 |
+ |
return pSource; |
|
354 |
+ |
} |
|
355 |
+ |
|
|
356 |
+ |
public static String defaultIfNull( String pTestString, String pDefault ) |
|
357 |
+ |
{ |
|
358 |
+ |
return isNullOrEmpty( pTestString ) ? pDefault : pTestString; |
|
359 |
+ |
} |
|
360 |
+ |
|
|
361 |
+ |
public static String normalizeNewLines( String pString ) |
|
362 |
+ |
{ |
|
363 |
+ |
pString = replace( pString, "\r\n", "\n" ); |
|
364 |
+ |
pString = replace( pString, "\n\r", "\n" ); |
|
365 |
+ |
pString = replace( pString, '\r', "\n" ); |
|
366 |
+ |
|
|
367 |
+ |
return pString; |
|
368 |
+ |
} |
|
369 |
+ |
|
|
370 |
+ |
public static String[] stringToLines( String pString ) |
|
371 |
+ |
{ |
|
372 |
+ |
return parseChar( replace( normalizeNewLines( pString ), "\f", "\n" ), '\n' ); |
|
373 |
+ |
} |
|
374 |
+ |
|
|
375 |
+ |
public static String linesToString( String[] pLines ) |
|
376 |
+ |
{ |
|
377 |
+ |
StringBuilder sb = new StringBuilder(); |
|
378 |
+ |
if ( pLines != null ) |
|
379 |
+ |
{ |
|
380 |
+ |
for ( String zLine : pLines ) |
|
381 |
+ |
{ |
|
382 |
+ |
sb.append( zLine ); |
|
383 |
+ |
sb.append( '\n' ); |
|
384 |
+ |
} |
|
385 |
+ |
} |
|
386 |
+ |
return sb.toString(); |
|
387 |
+ |
} |
|
388 |
+ |
|
|
389 |
+ |
public static String makeNonBlankLines( String pSource, int pLinesToMake ) |
|
390 |
+ |
{ |
|
391 |
+ |
pSource = normalizeNewLines( deNull( pSource ) ); |
|
392 |
+ |
StringBuilder sb = new StringBuilder(); |
|
393 |
+ |
for ( int i = 0; i < pLinesToMake; i++ ) |
|
394 |
+ |
{ |
|
395 |
+ |
int at = (pSource += '\n').indexOf( '\n' ); |
|
396 |
+ |
String line = pSource.substring( 0, at ); |
|
397 |
+ |
pSource = pSource.substring( at + 1 ); |
|
398 |
+ |
if ( sb.length() != 0 ) |
|
399 |
+ |
{ |
|
400 |
+ |
sb.append( '\n' ); |
|
401 |
+ |
} |
|
402 |
+ |
sb.append( line ).append( ' ' ); |
|
403 |
+ |
} |
|
404 |
+ |
return sb.toString(); |
|
405 |
+ |
} |
325 |
406 |
|
} |