Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
string.functions.cc
Go to the documentation of this file.
1 // String Functions
2 //
3 // Project: Objexx Fortran Compatibility Library (ObjexxFCL)
4 //
5 // Version: 3.0.0
6 //
7 // Language: C++
8 //
9 // Copyright (c) 2000-2009 Objexx Engineering, Inc. All Rights Reserved.
10 // Use of this source code or any derivative of it is restricted by license.
11 // Licensing is available from Objexx Engineering, Inc.: http://objexx.com Objexx@objexx.com
12 
13 
14 // ObjexxFCL Headers
16 
17 // C++ Headers
18 #include <algorithm>
19 #include <cctype>
20 #include <cstring>
21 
22 
23 namespace ObjexxFCL {
24 
25 
26 // Using
27 using std::string;
28 
29 
30 // Constants
31 char const SPACE( ' ' );
32 std::string const WHITESPACE( " \t\0", 3 );
33 
34 
35 // Predicate
36 
37 
38 /// @brief char == char Case-Insensitively (non-inline for use by equali below)?
39 bool
40 char_equali( char const c, char const d )
41 {
42  return ( std::tolower( c ) == std::tolower( d ) );
43 }
44 
45 
46 /// @brief string == string Case-Insensitively?
47 bool
48 equali( std::string const & s, std::string const & t )
49 {
50  if ( s.length() != t.length() ) {
51  return false;
52  } else {
53  return std::equal( s.begin(), s.end(), t.begin(), char_equali );
54  }
55 }
56 
57 
58 /// @brief string == cstring Case-Insensitively?
59 bool
60 equali( std::string const & s, c_cstring const t )
61 {
62  if ( s.length() != std::strlen( t ) ) {
63  return false;
64  } else {
65  return std::equal( s.begin(), s.end(), t, char_equali );
66  }
67 }
68 
69 
70 /// @brief cstring == string Case-Insensitively?
71 bool
72 equali( c_cstring const s, std::string const & t )
73 {
74  if ( std::strlen( s ) != t.length() ) {
75  return false;
76  } else {
77  return std::equal( t.begin(), t.end(), s, char_equali );
78  }
79 }
80 
81 
82 /// @brief Has a Prefix Case-Optionally?
83 bool
84 has_prefix( std::string const & s, std::string const & pre, bool const exact_case )
85 {
86  string::size_type const pre_len( pre.length() );
87  if ( pre_len == 0 ) {
88  return false;
89  } else if ( s.length() < pre_len ) {
90  return false;
91  } else if ( exact_case ) {
92  return ( s.find( pre ) == 0 );
93  } else {
94  return ( lowercased( s ).find( lowercased( pre ) ) == 0 );
95  }
96 }
97 
98 
99 /// @brief Has a Suffix Case-Optionally?
100 bool
101 has_suffix( std::string const & s, std::string const & suf, bool const exact_case )
102 {
103  string::size_type const suf_len( suf.length() );
104  if ( suf_len == 0 ) {
105  return false;
106  } else {
107  string::size_type const s_len( s.length() );
108  if ( s_len < suf_len ) {
109  return false;
110  } else if ( exact_case ) {
111  return ( s.rfind( suf ) == s_len - suf_len );
112  } else {
113  return ( lowercased( s ).rfind( lowercased( suf ) ) == s_len - suf_len );
114  }
115  }
116 }
117 
118 
119 // Modifier
120 
121 
122 /// @brief Lowercase a string
123 std::string &
124 lowercase( std::string & s )
125 {
126  string::size_type const s_len( s.length() );
127  for ( string::size_type i = 0; i < s_len; ++i ) {
128  s[ i ] = std::tolower( s[ i ] );
129  }
130  return s;
131 }
132 
133 
134 /// @brief Uppercase a string
135 std::string &
136 uppercase( std::string & s )
137 {
138  string::size_type const s_len( s.length() );
139  for ( string::size_type i = 0; i < s_len; ++i ) {
140  s[ i ] = std::toupper( s[ i ] );
141  }
142  return s;
143 }
144 
145 
146 /// @brief Left Justify a string
147 std::string &
148 left_justify( std::string & s )
149 {
150  string::size_type const off( s.find_first_not_of( SPACE ) );
151  if ( ( off > 0 ) && ( off != string::npos ) ) {
152  s.erase( 0, off ).append( off, SPACE );
153  }
154  return s;
155 }
156 
157 
158 /// @brief Right Justify a string
159 std::string &
160 right_justify( std::string & s )
161 {
162  string::size_type const s_len_trim( len_trim( s ) );
163  string::size_type const off( s.length() - s_len_trim );
164  if ( off > 0 ) {
165  s.erase( s_len_trim ).insert( 0, off, SPACE );
166  }
167  return s;
168 }
169 
170 
171 /// @brief Trim Trailing Space from a string
172 std::string &
173 trim( std::string & s )
174 {
175  if ( ! s.empty() ) {
176  string::size_type const ie( s.find_last_not_of( SPACE ) );
177  if ( ie == string::npos ) { // Blank string: return empty string
178  s.clear();
179  } else if ( ie + 1 < s.length() ) { // Trim tail
180  s.erase( ie + 1 );
181  }
182  }
183  return s;
184 }
185 
186 
187 /// @brief Trim Trailing Whitespace from a string
188 std::string &
189 trim_whitespace( std::string & s )
190 {
191  if ( ! s.empty() ) {
192  string::size_type const ie( s.find_last_not_of( WHITESPACE ) );
193  if ( ie == string::npos ) { // Blank string: return empty string
194  s.clear();
195  } else if ( ie + 1 < s.length() ) { // Trim tail
196  s.erase( ie + 1 );
197  }
198  }
199  return s;
200 }
201 
202 
203 /// @brief Strip Specified Characters from a string's Tails
204 std::string &
205 strip( std::string & s, std::string const & chars )
206 {
207  if ( ! s.empty() ) {
208  string::size_type const ib( s.find_first_not_of( chars ) );
209  string::size_type const ie( s.find_last_not_of( chars ) );
210  if ( ( ib == string::npos ) || ( ie == string::npos ) ) { // All of string is from chars
211  s.clear();
212  } else {
213  if ( ie < s.length() - 1 ) s.erase( ie + 1 );
214  if ( ib > 0 ) s.erase( 0, ib );
215  }
216  }
217  return s;
218 }
219 
220 
221 /// @brief Strip Specified Characters from a string's Left Tail
222 std::string &
223 lstrip( std::string & s, std::string const & chars )
224 {
225  if ( ! s.empty() ) {
226  string::size_type const ib( s.find_first_not_of( chars ) );
227  if ( ib == string::npos ) { // All of string is from chars
228  s.clear();
229  } else if ( ib > 0 ) {
230  s.erase( 0, ib );
231  }
232  }
233  return s;
234 }
235 
236 
237 /// @brief Strip Specified Characters from a string's Right Tail
238 std::string &
239 rstrip( std::string & s, std::string const & chars )
240 {
241  if ( ! s.empty() ) {
242  string::size_type const ie( s.find_last_not_of( chars ) );
243  if ( ie == string::npos ) { // All of string is from chars
244  s.clear();
245  } else {
246  if ( ie < s.length() - 1 ) s.erase( ie + 1 );
247  }
248  }
249  return s;
250 }
251 
252 
253 /// @brief Strip Space from a string's Tails
254 std::string &
255 strip( std::string & s )
256 {
257  if ( ! s.empty() ) {
258  string::size_type const ib( s.find_first_not_of( SPACE ) );
259  string::size_type const ie( s.find_last_not_of( SPACE ) );
260  if ( ( ib == string::npos ) || ( ie == string::npos ) ) { // All of string is SPACE
261  s.clear();
262  } else {
263  if ( ie < s.length() - 1 ) s.erase( ie + 1 );
264  if ( ib > 0 ) s.erase( 0, ib );
265  }
266  }
267  return s;
268 }
269 
270 
271 /// @brief Strip Space from a string's Left Tail
272 std::string &
273 lstrip( std::string & s )
274 {
275  if ( ! s.empty() ) {
276  string::size_type const ib( s.find_first_not_of( SPACE ) );
277  if ( ib == string::npos ) { // All of string is SPACE
278  s.clear();
279  } else if ( ib > 0 ) {
280  s.erase( 0, ib );
281  }
282  }
283  return s;
284 }
285 
286 
287 /// @brief Strip Space from a string's Right Tail
288 std::string &
289 rstrip( std::string & s )
290 {
291  if ( ! s.empty() ) {
292  string::size_type const ie( s.find_last_not_of( SPACE ) );
293  if ( ie == string::npos ) { // All of string is SPACE
294  s.clear();
295  } else {
296  if ( ie < s.length() - 1 ) s.erase( ie + 1 );
297  }
298  }
299  return s;
300 }
301 
302 
303 /// @brief Strip Whitespace from a string's Tails
304 std::string &
305 strip_whitespace( std::string & s )
306 {
307  if ( ! s.empty() ) {
308  string::size_type const ib( s.find_first_not_of( WHITESPACE ) );
309  string::size_type const ie( s.find_last_not_of( WHITESPACE ) );
310  if ( ( ib == string::npos ) || ( ie == string::npos ) ) { // All of string is from WHITESPACE
311  s.clear();
312  } else {
313  if ( ie < s.length() - 1 ) s.erase( ie + 1 );
314  if ( ib > 0 ) s.erase( 0, ib );
315  }
316  }
317  return s;
318 }
319 
320 
321 /// @brief Strip Whitespace from a string's Left Tail
322 std::string &
323 lstrip_whitespace( std::string & s )
324 {
325  if ( ! s.empty() ) {
326  string::size_type const ib( s.find_first_not_of( WHITESPACE ) );
327  if ( ib == string::npos ) { // All of string is from WHITESPACE
328  s.clear();
329  } else if ( ib > 0 ) {
330  s.erase( 0, ib );
331  }
332  }
333  return s;
334 }
335 
336 
337 /// @brief Strip Whitespace from a string's Right Tail
338 std::string &
339 rstrip_whitespace( std::string & s )
340 {
341  if ( ! s.empty() ) {
342  string::size_type const ie( s.find_last_not_of( WHITESPACE ) );
343  if ( ie == string::npos ) { // All of string is from WHITESPACE
344  s.clear();
345  } else {
346  if ( ie < s.length() - 1 ) s.erase( ie + 1 );
347  }
348  }
349  return s;
350 }
351 
352 
353 /// @brief Pad a string to a Specified Length
354 std::string &
355 pad( std::string & s, std::string::size_type const len )
356 {
357  string::size_type const s_len( s.length() );
358  if ( s_len < len ) { // Pad
359  s.append( len - s_len, SPACE );
360  }
361  return s;
362 }
363 
364 
365 /// @brief Left-Pad a string to a Specified Length
366 std::string &
367 lpad( std::string & s, std::string::size_type const len )
368 {
369  string::size_type const s_len( s.length() );
370  if ( s_len < len ) { // Left-pad
371  s.insert( static_cast< string::size_type >( 0 ), len - s_len, SPACE );
372  }
373  return s;
374 }
375 
376 
377 /// @brief Right-Pad a string to a Specified Length
378 std::string &
379 rpad( std::string & s, std::string::size_type const len )
380 {
381  string::size_type const s_len( s.length() );
382  if ( s_len < len ) { // Pad
383  s.append( len - s_len, SPACE );
384  }
385  return s;
386 }
387 
388 
389 /// @brief Size a string to a Specified Length
390 std::string &
391 size( std::string & s, std::string::size_type const len )
392 {
393  string::size_type const s_len( s.length() );
394  if ( s_len < len ) { // Pad
395  s.append( len - s_len, SPACE );
396  } else if ( s_len > len ) { // Truncate
397  s.erase( len );
398  }
399  return s;
400 }
401 
402 
403 /// @brief Center a string wrt its Whitespace
404 std::string &
405 center( std::string & s )
406 {
407  string::size_type const s_len( s.length() );
408  s = centered( strip_whitespace( s ), s_len );
409  return s;
410 }
411 
412 
413 /// @brief Center a string with a Specified Length
414 std::string &
415 center( std::string & s, std::string::size_type const len )
416 {
417  string::size_type const s_len( s.length() );
418  if ( s_len < len ) { // Pad
419  string::size_type const off( ( len - s_len ) / 2 );
420  s = string( off, SPACE ).append( s ).append( string( len - s_len - off, SPACE ) );
421  } else if ( s_len > len ) { // Truncate
422  s.erase( len );
423  }
424  return s;
425 }
426 
427 
428 /// @brief Remove Repeat Characters from a Possibly Unsorted string Preserving Order
429 std::string &
430 unique( std::string & s )
431 {
432  string u;
433  string::size_type const s_len( s.length() );
434  for ( string::size_type i = 0; i < s_len; ++i ) {
435  if ( u.find( s[ i ] ) == string::npos ) {
436  u.push_back( s[ i ] );
437  }
438  }
439  s.swap( u );
440  return s;
441 }
442 
443 
444 /// @brief Overlay a string With Another string, Expanding Size as Needed
445 std::string &
446 overlay( std::string & s, std::string const & t, std::string::size_type const pos )
447 {
448  std::string::size_type const t_len( t.length() );
449  std::string::size_type const l_len( pos + t_len ); // Lower bound on new string length
450  if ( l_len > s.length() ) s.resize( l_len, ' ' ); // Expand
451  s.replace( pos, t_len, t ); // Overlay the string
452  return s;
453 }
454 
455 
456 // Generator
457 
458 
459 /// @brief Lowercased Copy of a string
460 std::string
461 lowercased( std::string const & s )
462 {
463  string t( s );
464  string::size_type const t_len( t.length() );
465  for ( string::size_type i = 0; i < t_len; ++i ) {
466  t[ i ] = std::tolower( t[ i ] );
467  }
468  return t;
469 }
470 
471 
472 /// @brief Uppercased Copy of a string
473 std::string
474 uppercased( std::string const & s )
475 {
476  string t( s );
477  string::size_type const t_len( t.length() );
478  for ( string::size_type i = 0; i < t_len; ++i ) {
479  t[ i ] = std::toupper( t[ i ] );
480  }
481  return t;
482 }
483 
484 
485 /// @brief Left-Justified Copy of a string
486 std::string
487 left_justified( std::string const & s )
488 {
489  string::size_type const off( s.find_first_not_of( SPACE ) );
490  if ( ( off > 0 ) && ( off != string::npos ) ) {
491  return s.substr( off ).append( off, SPACE );
492  } else {
493  return s;
494  }
495 }
496 
497 
498 /// @brief Right-Justified Copy of a string
499 std::string
500 right_justified( std::string const & s )
501 {
502  string::size_type const s_len_trim( len_trim( s ) );
503  string::size_type const off( s.length() - s_len_trim );
504  if ( off > 0 ) {
505  return string( off, SPACE ).append( s.substr( 0, s_len_trim ) );
506  } else {
507  return s;
508  }
509 }
510 
511 
512 /// @brief Trailing Space Trimmed Copy of a string
513 std::string
514 trimmed( std::string const & s )
515 {
516  if ( s.empty() ) { // Empty string
517  return s;
518  } else {
519  string::size_type const ie( s.find_last_not_of( SPACE ) );
520  if ( ie == string::npos ) { // Blank string: return empty string
521  return string();
522  } else if ( ie < s.length() - 1 ) { // Trimmed
523  return s.substr( 0, ie + 1 );
524  } else { // Unchanged
525  return s;
526  }
527  }
528 }
529 
530 
531 /// @brief Trailing Whitespace Trimmed Copy of a string
532 std::string
533 trimmed_whitespace( std::string const & s )
534 {
535  if ( s.empty() ) { // Empty string
536  return s;
537  } else {
538  string::size_type const ie( s.find_last_not_of( WHITESPACE ) );
539  if ( ie == string::npos ) { // Blank string: return empty string
540  return string();
541  } else if ( ie < s.length() - 1 ) { // Trimmed
542  return s.substr( 0, ie + 1 );
543  } else { // Unchanged
544  return s;
545  }
546  }
547 }
548 
549 
550 /// @brief Specified Characters Stripped from a string's Tails Copy of a string
551 std::string
552 stripped( std::string const & s, std::string const & chars )
553 {
554  if ( s.empty() ) {
555  return s;
556  } else {
557  string::size_type const ib( s.find_first_not_of( chars ) );
558  string::size_type const ie( s.find_last_not_of( chars ) );
559  if ( ( ib == string::npos ) || ( ie == string::npos ) ) { // All of string is from chars
560  return string(); // Return empty string
561  } else {
562  return s.substr( ib, ie - ib + 1 );
563  }
564  }
565 }
566 
567 
568 /// @brief Specified Characters Stripped from a string's Left Tail Copy of a string
569 std::string
570 lstripped( std::string const & s, std::string const & chars )
571 {
572  if ( s.empty() ) {
573  return s;
574  } else {
575  string::size_type const ib( s.find_first_not_of( chars ) );
576  if ( ib == string::npos ) { // All of string is from chars
577  return string(); // Return empty string
578  } else if ( ib > 0 ) {
579  return s.substr( ib );
580  } else {
581  return s;
582  }
583  }
584 }
585 
586 
587 /// @brief Specified Characters Stripped from a string's Right Tail Copy of a string
588 std::string
589 rstripped( std::string const & s, std::string const & chars )
590 {
591  if ( s.empty() ) {
592  return s;
593  } else {
594  string::size_type const ie( s.find_last_not_of( chars ) );
595  if ( ie == string::npos ) { // All of string is from chars
596  return string(); // Return empty string
597  } else {
598  return s.substr( 0, ie + 1 );
599  }
600  }
601 }
602 
603 
604 /// @brief Space Stripped from a string's Tails Copy of a string
605 std::string
606 stripped( std::string const & s )
607 {
608  if ( s.empty() ) {
609  return s;
610  } else {
611  string::size_type const ib( s.find_first_not_of( SPACE ) );
612  string::size_type const ie( s.find_last_not_of( SPACE ) );
613  if ( ( ib == string::npos ) || ( ie == string::npos ) ) { // All of string is SPACE
614  return string(); // Return empty string
615  } else {
616  return s.substr( ib, ie - ib + 1 );
617  }
618  }
619 }
620 
621 
622 /// @brief Space Stripped from a string's Left Tail Copy of a string
623 std::string
624 lstripped( std::string const & s )
625 {
626  if ( s.empty() ) {
627  return s;
628  } else {
629  string::size_type const ib( s.find_first_not_of( SPACE ) );
630  if ( ib == string::npos ) { // All of string is SPACE
631  return string(); // Return empty string
632  } else if ( ib > 0 ) {
633  return s.substr( ib );
634  } else {
635  return s;
636  }
637  }
638 }
639 
640 
641 /// @brief Space Stripped from a string's Right Tail Copy of a string
642 std::string
643 rstripped( std::string const & s )
644 {
645  if ( s.empty() ) {
646  return s;
647  } else {
648  string::size_type const ie( s.find_last_not_of( SPACE ) );
649  if ( ie == string::npos ) { // All of string is SPACE
650  return string(); // Return empty string
651  } else {
652  return s.substr( 0, ie + 1 );
653  }
654  }
655 }
656 
657 
658 /// @brief Whitespace Stripped from a string's Tails Copy of a string
659 std::string
660 stripped_whitespace( std::string const & s )
661 {
662  if ( s.empty() ) {
663  return s;
664  } else {
665  string::size_type const ib( s.find_first_not_of( WHITESPACE ) );
666  string::size_type const ie( s.find_last_not_of( WHITESPACE ) );
667  if ( ( ib == string::npos ) || ( ie == string::npos ) ) { // All of string is from WHITESPACE
668  return string(); // Return empty string
669  } else {
670  return s.substr( ib, ie - ib + 1 );
671  }
672  }
673 }
674 
675 
676 /// @brief Whitespace Stripped from a string's Left Tail Copy of a string
677 std::string
678 lstripped_whitespace( std::string const & s )
679 {
680  if ( s.empty() ) {
681  return s;
682  } else {
683  string::size_type const ib( s.find_first_not_of( WHITESPACE ) );
684  if ( ib == string::npos ) { // All of string is from WHITESPACE
685  return string(); // Return empty string
686  } else if ( ib > 0 ) {
687  return s.substr( ib );
688  } else {
689  return s;
690  }
691  }
692 }
693 
694 
695 /// @brief Whitespace Stripped from a string's Right Tail Copy of a string
696 std::string
697 rstripped_whitespace( std::string const & s )
698 {
699  if ( s.empty() ) {
700  return s;
701  } else {
702  string::size_type const ie( s.find_last_not_of( WHITESPACE ) );
703  if ( ie == string::npos ) { // All of string is from WHITESPACE
704  return string(); // Return empty string
705  } else {
706  return s.substr( 0, ie + 1 );
707  }
708  }
709 }
710 
711 
712 /// @brief Padded to a Specified Length Copy of a string
713 std::string
714 padded( std::string const & s, std::string::size_type const len )
715 {
716  string::size_type const s_len( s.length() );
717  if ( s_len < len ) { // Padded
718  return s + string( len - s_len, SPACE );
719  } else { // Unchanged
720  return s;
721  }
722 }
723 
724 
725 /// @brief Left-Padded to a Specified Length Copy of a string
726 std::string
727 lpadded( std::string const & s, std::string::size_type const len )
728 {
729  string::size_type const s_len( s.length() );
730  if ( s_len < len ) { // Left-padded
731  return string( len - s_len, SPACE ).append( s );
732  } else { // Unchanged
733  return s;
734  }
735 }
736 
737 
738 /// @brief Right-Padded to a Specified Length Copy of a string
739 std::string
740 rpadded( std::string const & s, std::string::size_type const len )
741 {
742  string::size_type const s_len( s.length() );
743  if ( s_len < len ) { // Padded
744  return s + string( len - s_len, SPACE );
745  } else { // Unchanged
746  return s;
747  }
748 }
749 
750 
751 /// @brief Sized to a Specified Length Copy of a string
752 std::string
753 sized( std::string const & s, std::string::size_type const len )
754 {
755  string::size_type const s_len( s.length() );
756  if ( s_len < len ) { // Padded
757  return s + string( len - s_len, SPACE );
758  } else if ( s_len == len ) { // Unchanged
759  return s;
760  } else { // Truncated
761  return s.substr( 0, len );
762  }
763 }
764 
765 
766 /// @brief Centered wrt Whitespace Copy of a string
767 std::string
768 centered( std::string const & s )
769 {
770  return centered( stripped_whitespace( s ), s.length() );
771 }
772 
773 
774 /// @brief Centered in a string of Specified Length Copy of a string
775 std::string
776 centered( std::string const & s, std::string::size_type const len )
777 {
778  string::size_type const s_len( s.length() );
779  if ( s_len < len ) { // Padded
780  string::size_type const off( ( len - s_len ) / 2 );
781  return string( off, SPACE ).append( s ).append( string( len - s_len - off, SPACE ) );
782  } else if ( s_len == len ) { // Unchanged
783  return s;
784  } else { // Truncated
785  return s.substr( 0, len );
786  }
787 }
788 
789 
790 /// @brief Removed Repeat Characters from a Possibly Unsorted string Preserving Order Copy of a string
791 std::string
792 uniqued( std::string const & s )
793 {
794  string u;
795  string::size_type const s_len( s.length() );
796  for ( string::size_type i = 0; i < s_len; ++i ) {
797  if ( u.find( s[ i ] ) == string::npos ) {
798  u.push_back( s[ i ] );
799  }
800  }
801  return u;
802 }
803 
804 
805 /// @brief Space-Free Head Copy of a string
806 std::string
807 head( std::string const & s )
808 {
809  if ( s.empty() ) { // Empty string
810  return s;
811  } else {
812  string::size_type const ie( s.find( SPACE ) );
813  if ( ie == string::npos ) { // Space-free string
814  return s;
815  } else {
816  return s.substr( 0, ie );
817  }
818  }
819 }
820 
821 
822 /// @brief ints of a string (e.g., allowing "5-8" to represent "5 6 7 8").
823 bool
824 is_ints( std::string const & s ){
825  bool string_is_ok( false );
826  ints_of( s, string_is_ok );
827  return string_is_ok;
828 }
829 
830 /// @brief ints of a string (e.g., allowing "5-8" to represent "5 6 7 8").
831 std::vector< int >
832 ints_of( std::string const & s ){
833  bool string_is_ok( false );
834  return ints_of( s, string_is_ok );
835 }
836 
837 /// @brief ints of a string (e.g., allowing "5-8" to represent "5 6 7 8").
838 /// new -- allow comma separation.
839 std::vector< int >
840 ints_of( std::string const & s_input, bool & string_is_ok ){
841 
842  std::vector< int > vals;
843  string_is_ok = false;
844 
845  std::string s( s_input );
846 
847  // comma parsing:
848  while( s.find( ',' ) != std::string::npos ){
849  std::vector< int > vals_up_to_comma = ints_of( s.substr( 0, s.find( ',' ) ) /* tag up to the comma*/ );
850  for ( unsigned n = 0; n < vals_up_to_comma.size(); n++ ) vals.push_back( vals_up_to_comma[ n ] );
851  s = s.substr( s.find( ',' )+1 ); // tag after the comma.
852  }
853 
854  size_t found_dash = s.find( "-" );
855  if ( found_dash == 0 ) found_dash = s.substr(1).find("-") + 1;
856  if ( found_dash == std::string::npos || found_dash == 0 ){
857 
858  string_is_ok = is_int( s );
859  if ( string_is_ok ) vals.push_back( int_of( s ) );
860 
861  } else {
862  std::string const start_val_string = s.substr(0,found_dash );
863  std::string const end_val_string = s.substr(found_dash+1, s.size() );
864  string_is_ok = is_int( start_val_string ) && is_int( end_val_string); // currently cannot process
865  if ( string_is_ok ){
866  int start_val = int_of( start_val_string );
867  int end_val = int_of( end_val_string );
868  for ( int n = start_val; n <= end_val; n++ ) vals.push_back( n );
869  }
870  }
871 
872  return vals;
873 }
874 
875 
876 } // namespace ObjexxFCL
std::string & size(std::string &s, std::string::size_type const len)
Size a string to a Specified Length.
bool char_equali(char const c, char const d)
char == char Case-Insensitively (non-inline for use by equali below)?
char lowercased(char const c)
Lowercased Copy of a Character.
bool has_suffix(std::string const &s, std::string const &suf, bool const exact_case)
Has a Suffix Case-Optionally?
std::string stripped_whitespace(std::string const &s)
Whitespace Stripped from a string's Tails Copy of a string.
std::string & strip_whitespace(std::string &s)
Strip Whitespace from a string's Tails.
std::string & trim_whitespace(std::string &s)
Trim Trailing Whitespace from a string.
std::string & overlay(std::string &s, std::string const &t, std::string::size_type const pos)
Overlay a string With Another string, Expanding Size as Needed.
std::string rstripped(std::string const &s, std::string const &chars)
Specified Characters Stripped from a string's Right Tail Copy of a string.
bool has_prefix(std::string const &s, std::string const &pre, bool const exact_case)
Has a Prefix Case-Optionally?
char & lowercase(char &c)
Lowercase a Character.
std::string & lstrip_whitespace(std::string &s)
Strip Whitespace from a string's Left Tail.
Fstring::size_type len(Fstring const &s)
Length.
Definition: Fstring.hh:2207
bool is_ints(std::string const &s)
ints of a string (e.g., allowing "5-8" to represent "5 6 7 8").
char const * c_cstring
bool equali(char const c, char const d)
char == char Case-Insensitively
std::string & rstrip_whitespace(std::string &s)
Strip Whitespace from a string's Right Tail.
std::string padded(std::string const &s, std::string::size_type const len)
Padded to a Specified Length Copy of a string.
std::string & pad(std::string &s, std::string::size_type const len)
Pad a string to a Specified Length.
std::string & strip(std::string &s, std::string const &chars)
Strip Specified Characters from a string's Tails.
std::string head(std::string const &s)
Space-Free Head Copy of a string.
std::string trimmed_whitespace(std::string const &s)
Trailing Whitespace Trimmed Copy of a string.
std::string rpadded(std::string const &s, std::string::size_type const len)
Right-Padded to a Specified Length Copy of a string.
bool equal(char const c, char const d, bool const exact_case)
char == char Case-Optionally?
std::string & trim(std::string &s)
Trim Trailing Space from a string.
Fstring::size_type len_trim(Fstring const &s)
Length Space-Trimmed.
Definition: Fstring.hh:2216
std::string & lpad(std::string &s, std::string::size_type const len)
Left-Pad a string to a Specified Length.
std::string uniqued(std::string const &s)
Removed Repeat Characters from a Possibly Unsorted string Preserving Order Copy of a string...
std::string & unique(std::string &s)
Remove Repeat Characters from a Possibly Unsorted string Preserving Order.
std::string left_justified(std::string const &s)
Left-Justified Copy of a string.
std::string & rpad(std::string &s, std::string::size_type const len)
Right-Pad a string to a Specified Length.
std::string & lstrip(std::string &s, std::string const &chars)
Strip Specified Characters from a string's Left Tail.
std::vector< int > ints_of(std::string const &s)
ints of a string (e.g., allowing "5-8" to represent "5 6 7 8").
std::string stripped(std::string const &s, std::string const &chars)
Specified Characters Stripped from a string's Tails Copy of a string.
bool is_int(Fstring const &s)
Fstring is Readable as an int?
Definition: Fstring.hh:2676
std::string lpadded(std::string const &s, std::string::size_type const len)
Left-Padded to a Specified Length Copy of a string.
std::string centered(std::string const &s)
Centered wrt Whitespace Copy of a string.
Fstring center(Fstring const &s)
Centered Copy.
Definition: Fstring.hh:2431
std::string & right_justify(std::string &s)
Right Justify a string.
std::string rstripped_whitespace(std::string const &s)
Whitespace Stripped from a string's Right Tail Copy of a string.
int int_of(Fstring const &s)
int of an Fstring
Definition: Fstring.hh:2808
std::string lstripped(std::string const &s, std::string const &chars)
Specified Characters Stripped from a string's Left Tail Copy of a string.
Fstring trimmed(Fstring const &s)
Space-Trimmed Copy.
Definition: Fstring.hh:2225
std::string & rstrip(std::string &s, std::string const &chars)
Strip Specified Characters from a string's Right Tail.
std::string sized(std::string const &s, std::string::size_type const len)
Sized to a Specified Length Copy of a string.
char const SPACE( ' ')
char uppercased(char const c)
Uppercased Copy of a Character.
char & uppercase(char &c)
Uppercase a Character.
std::string right_justified(std::string const &s)
Right-Justified Copy of a string.
std::string lstripped_whitespace(std::string const &s)
Whitespace Stripped from a string's Left Tail Copy of a string.
std::string & left_justify(std::string &s)
Left Justify a string.
std::string const WHITESPACE(" \t\0", 3)