Strings.f90 49.6 KB
Newer Older
1
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
2
3
4
5
6
7
!                          Futility Development Group                          !
!                             All rights reserved.                             !
!                                                                              !
! Futility is a jointly-maintained, open-source project between the University !
! of Michigan and Oak Ridge National Laboratory.  The copyright and license    !
! can be found in LICENSE.txt in the head directory of this repository.        !
8
9
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
!> @brief Module for specifying a type for arbitrary length strings
10
!>
11
!> This module defines a type for a string which can be an arbitrary length.
12
!> It then provides overloaded operators and intrinsic functions so
13
!> that it can be used almost exactly like a Fortran @c CHARACTER type variable.
14
!>
15
16
17
18
19
20
21
!> The following operators have been overloaded for use with @c StringType
!>  - @c ASSIGNMENT(=)
!>  - @c OPERATOR(//)
!>  - @c OPERATOR(==)
!>  - @c OPERATOR(/=)
!>
!> The following intrinsic Fortran functions have been overloaded for use with
22
!> @c StringType
23
24
25
26
27
!>  - @ref Strings::LEN_StringType "LEN": @copybrief Strings::LEN_StringType
!>  - @ref Strings::LEN_TRIM_StringType "LEN_TRIM": @copybrief Strings::LEN_TRIM_StringType
!>  - @ref Strings::TRIM_StringType "TRIM": @copybrief Strings::TRIM_StringType
!>  - @ref Strings::ADJUSTL_StringType "ADJUSTL": @copybrief Strings::ADJUSTL_StringType
!>  - @ref Strings::ADJUSTR_StringType "ADJUSTR": @copybrief Strings::ADJUSTR_StringType
28
!>  - @c INDEX
29
30
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
MODULE Strings
HendersonSC's avatar
HendersonSC committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
USE ISO_C_BINDING
USE IntrType
IMPLICIT NONE
PRIVATE

PUBLIC :: StringType
PUBLIC :: CHAR
PUBLIC :: LEN
PUBLIC :: LEN_TRIM
PUBLIC :: TRIM
PUBLIC :: ADJUSTL
PUBLIC :: ADJUSTR
PUBLIC :: INDEX
PUBLIC :: ASSIGNMENT(=)
PUBLIC :: OPERATOR(//)
PUBLIC :: OPERATOR(==)
PUBLIC :: OPERATOR(/=)
Graham, Aaron's avatar
Graham, Aaron committed
48
49
50
51
PUBLIC :: OPERATOR(<)
PUBLIC :: OPERATOR(>)
PUBLIC :: OPERATOR(<=)
PUBLIC :: OPERATOR(>=)
HendersonSC's avatar
HendersonSC committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

!> Derived type for an arbitrary length string
TYPE :: StringType
  !> The stored intrinsic character string
  CHARACTER(LEN=:),ALLOCATABLE,PRIVATE :: s
  CONTAINS
    !> copybrief Strings::toupper_string
    !> copydetails Strings::toupper_string
    PROCEDURE,PASS :: upper => toupper_string
    !> copybrief Strings::toLower_string
    !> copydetails Strings::toLower_string
    PROCEDURE,PASS :: lower => toLower_string
    !> copybrief Strings::at_string
    !> copydetails Strings::at_string
    PROCEDURE,PASS :: at => at_string
    !> copybrief Strings::substr_str
    !> copydetails Strings::substr_str
    PROCEDURE,PASS :: substr => substr_str
    !> copybrief Strings::replace_slice
    !> copydetails Strings::replace_slice
    PROCEDURE,PASS,PRIVATE :: replace_slice
    !> copybrief Strings::replace_pattern
    !> copydetails Strings::replace_pattern
    PROCEDURE,PASS,PRIVATE :: replace_pattern
    GENERIC :: replace => replace_slice,replace_pattern
    !> copybrief Strings:: split_string
    !> copydetails Strings:: split_string
    PROCEDURE,PASS,PRIVATE :: split_string
    !> copybrief Strings::split_string_space
    !> copydetails Strings::split_string_space
    PROCEDURE,PASS,PRIVATE :: split_string_space
    GENERIC :: split => split_string, split_string_space
84
85
    !> copybrief Strings::partition
    !> copydetails Strings::partition
86
    PROCEDURE,PASS :: partition
87
88
89
    !> copybrief Strings::rPartition
    !> copydetails Strings::rPartition
    PROCEDURE,PASS :: rPartition
HendersonSC's avatar
HendersonSC committed
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    !> copybrief Strings::assign_char_to_StringType
    !> copydetails Strings::assign_char_to_StringType
    PROCEDURE,PASS,PRIVATE :: assign_char_to_StringType
    !> @copybrief Strings::assign_Short_Integer_to_StringType
    !> @copydetails Strings::assign_Short_Integer_to_StringType
    PROCEDURE,PASS,PRIVATE :: assign_Short_Integer_to_StringType
    !> @copybrief Strings::assign_Long_Integer_to_StringType
    !> @copydetails Strings::assign_Long_Integer_to_StringType
    PROCEDURE,PASS,PRIVATE :: assign_Long_Integer_to_StringType
    !> @copybrief Strings::assign_Single_Real_to_StringType
    !> @copydetails Strings::assign_Single_Real_to_StringType
    PROCEDURE,PASS,PRIVATE :: assign_Single_Real_to_StringType
    !> @copybrief Strings::assign_Double_Real_to_StringType
    !> @copydetails Strings::assign_Double_Real_to_StringType
    PROCEDURE,PASS,PRIVATE :: assign_Double_Real_to_StringType
    !> copybrief Strings::assign_Logical_to_StringType
    !> copydetails Strings::assign_Logical_to_StringType
    PROCEDURE,PASS,PRIVATE :: assign_Logical_to_StringType
    GENERIC :: ASSIGNMENT(=) => assign_char_to_StringType, &
        assign_Logical_to_StringType,assign_Single_Real_to_StringType, &
        assign_Double_Real_to_StringType,assign_Short_Integer_to_StringType, &
Graham, Aaron's avatar
Graham, Aaron committed
111
            assign_Long_Integer_to_StringType
HendersonSC's avatar
HendersonSC committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    !> copybrief Strings::str_to_sik
    !> copydetails Strings::str_to_sik
    PROCEDURE,PASS :: str_to_sik
    GENERIC :: stoi => str_to_sik
    !> copybrief Strings::str_to_srk
    !> copydetails Strings::str_to_srk
    PROCEDURE,PASS :: str_to_srk
    GENERIC :: stof => str_to_srk
    !> copybrief Strings::isInteger
    !> copydetails Strings::isInteger
    PROCEDURE,PASS :: isInteger
    !> copybrief Strings::isFloat
    !> copydetails Strings::isFloat
    PROCEDURE,PASS :: isFloat
    !> copybrief Strings::isNumeric_str
    !> copydetails Strings::isNumeric_str
    PROCEDURE,PASS :: isNumeric => isNumeric_str
129
130
    !> copybrief Strings::clear_str
    !> copydetails Strings::clear_str
HendersonSC's avatar
HendersonSC committed
131
    PROCEDURE,PASS :: clear => clear_str
132
133
134
    !> copybrief Strings::clean_str
    !> copydetails Strings::clean_str
    !FINAL :: clean_str
HendersonSC's avatar
HendersonSC committed
135
136
ENDTYPE StringType

137
138
139
140
141
142
INTERFACE StringType
  !> @copybrief Strings::charToStringType
  !> @copydetails Strings::charToStringType
  MODULE PROCEDURE charToStringType
ENDINTERFACE

HendersonSC's avatar
HendersonSC committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
!> @brief Overloads the Fortran intrinsic procedure CHAR() so
!> a string type argument may be passed.
INTERFACE CHAR
  !> @copybrief Strings::CHAR_StringType
  !> @copydetails Strings::CHAR_StringType
  MODULE PROCEDURE CHAR_StringType
  !> copybrief Strings::cchar_to_fchar
  !> copydetails Strings::cchar_to_fchar
  MODULE PROCEDURE cchar_to_fchar
ENDINTERFACE

!> @brief Overloads the Fortran intrinsic procedure LEN() so
!> a string type argument may be passed.
INTERFACE LEN
  !> @copybrief Strings::LEN_StringType
  !> @copydetails Strings::LEN_StringType
  MODULE PROCEDURE LEN_StringType
ENDINTERFACE

!> @brief Overloads the Fortran intrinsic procedure LEN_TRIM() so
!> a string type argument may be passed.
INTERFACE LEN_TRIM
  !> @copybrief Strings::LEN_TRIM_StringType
  !> @copydetails Strings::LEN_TRIM_StringType
  MODULE PROCEDURE LEN_TRIM_StringType
ENDINTERFACE

!> @brief Overloads the Fortran intrinsic procedure TRIM() so
!> a string type argument may be passed.
INTERFACE TRIM
  !> @copybrief Strings::TRIM_StringType
  !> @copydetails Strings::TRIM_StringType
  MODULE PROCEDURE TRIM_StringType
ENDINTERFACE

!> @brief Overloads the Fortran intrinsic procedure ADJUSTL() so
!> a string type argument may be passed.
INTERFACE ADJUSTL
  !> @copybrief Strings::ADJUSTL_StringType
  !> @copydetails Strings::ADJUSTL_StringType
  MODULE PROCEDURE ADJUSTL_StringType
ENDINTERFACE

!> @brief Overloads the Fortran intrinsic procedure ADJUSTR() so
!> a string type argument may be passed.
INTERFACE ADJUSTR
  !> @copybrief Strings::ADJUSTR_StringType
  !> @copydetails Strings::ADJUSTR_StringType
  MODULE PROCEDURE ADJUSTR_StringType
ENDINTERFACE

!> @brief Overloads the Fortran intrinsic procedure INDEX() so
!> string type arguments may be passed.
INTERFACE INDEX
  !> @copybrief Strings::INDEX_StringType_char
  !> @copydetails Strings::INDEX_StringType_char
  MODULE PROCEDURE INDEX_StringType_char
  !> @copybrief Strings::INDEX_char_StringType
  !> @copydetails Strings::INDEX_char_StringType
  MODULE PROCEDURE INDEX_char_StringType
  !> @copybrief Strings::INDEX_StringType_StringType
  !> @copydetails Strings::INDEX_StringType_StringType
  MODULE PROCEDURE INDEX_StringType_StringType
ENDINTERFACE

!> @brief Overloads the Fortran intrinsic operator for concatenating
!> character strings.
INTERFACE OPERATOR(//)
  !> @copybrief Strings::concatenate_char_onto_StringType
  !> @copydetails Strings::concatenate_char_onto_StringType
  MODULE PROCEDURE concatenate_char_onto_StringType
  !> @copybrief Strings::concatenate_StringType_onto_char
  !> @copydetails Strings::concatenate_StringType_onto_char
  MODULE PROCEDURE concatenate_StringType_onto_char
  !> @copybrief Strings::concatenate_StringType_onto_StringType
  !> @copydetails Strings::concatenate_StringType_onto_StringType
  MODULE PROCEDURE concatenate_StringType_onto_StringType
ENDINTERFACE

!> @brief Overloads the Fortran intrinsic operator for comparing
!> two variables to see if they are equal
INTERFACE OPERATOR(==)
  !> @copybrief Strings::equalto_char_StringType
  !> @copydetails Strings::equalto_char_StringType
  MODULE PROCEDURE equalto_char_StringType
  !> @copybrief Strings::equalto_StringType_char
  !> @copydetails Strings::equalto_StringType_char
  MODULE PROCEDURE equalto_StringType_char
  !> @copybrief Strings::equalto_StringType_StringType
  !> @copydetails Strings::equalto_StringType_StringType
  MODULE PROCEDURE equalto_StringType_StringType
ENDINTERFACE

!> @brief Overloads the Fortran intrinsic operator for comparing
!> two variables to see if they are not equal
INTERFACE OPERATOR(/=)
  !> @copybrief Strings::notequalto_char_StringType
  !> @copydetails Strings::notequalto_char_StringType
  MODULE PROCEDURE notequalto_char_StringType
  !> @copybrief Strings::notequalto_StringType_char
  !> @copydetails Strings::notequalto_StringType_char
  MODULE PROCEDURE notequalto_StringType_char
  !> @copybrief Strings::notequalto_StringType_StringType
  !> @copydetails Strings::notequalto_StringType_StringType
  MODULE PROCEDURE notequalto_StringType_StringType
ENDINTERFACE
Graham, Aaron's avatar
Graham, Aaron committed
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316

!> @brief Overloads the Fortran intrinsic operator for comparing
!> two variables to see if one is less than the other
!>
!> NOTE: This assumes that the system is using ASCII ordering and
!> that this is therefore equal to LLT (lexical less than).
INTERFACE OPERATOR(<)
  !> @copybrief Strings::lessthan_char_StringType
  !> @copydetails Strings::lessthan_char_StringType
  MODULE PROCEDURE lessthan_char_StringType
  !> @copybrief Strings::lessthan_StringType_char
  !> @copydetails Strings::lessthan_StringType_char
  MODULE PROCEDURE lessthan_StringType_char
  !> @copybrief Strings::lessthan_StringType_StringType
  !> @copydetails Strings::lessthan_StringType_StringType
  MODULE PROCEDURE lessthan_StringType_StringType
ENDINTERFACE

!> @brief Overloads the Fortran intrinsic operator for comparing
!> two variables to see one is greater than the other
!>
!> NOTE: This assumes that the system is using ASCII ordering and
!> that this is therefore equal to LGT (lexical greater than).
INTERFACE OPERATOR(>)
  !> @copybrief Strings::greaterthan_char_StringType
  !> @copydetails Strings::greaterthan_char_StringType
  MODULE PROCEDURE greaterthan_char_StringType
  !> @copybrief Strings::greaterthan_StringType_char
  !> @copydetails Strings::greaterthan_StringType_char
  MODULE PROCEDURE greaterthan_StringType_char
  !> @copybrief Strings::greaterthan_StringType_StringType
  !> @copydetails Strings::greaterthan_StringType_StringType
  MODULE PROCEDURE greaterthan_StringType_StringType
ENDINTERFACE

!> @brief Overloads the Fortran intrinsic operator for comparing
!> two variables to see if one is less than or equal to the other
!>
!> NOTE: This assumes that the system is using ASCII ordering and
!> that this is therefore equal to LLE (lexical less than/equal to).
INTERFACE OPERATOR(<=)
  !> @copybrief Strings::lessthanequal_char_StringType
  !> @copydetails Strings::lessthanequal_char_StringType
  MODULE PROCEDURE lessthanequal_char_StringType
  !> @copybrief Strings::lessthanequal_StringType_char
  !> @copydetails Strings::lessthanequal_StringType_char
  MODULE PROCEDURE lessthanequal_StringType_char
  !> @copybrief Strings::lessthanequal_StrinequalgType_StringType
  !> @copydetails Strings::lessthanequal_StrinequalgType_StringType
  MODULE PROCEDURE lessthanequal_StringType_StringType
ENDINTERFACE

!> @brief Overloads the Fortran intrinsic operator for comparing
!> two variables to see one is greater than or equal to the other
!>
!> NOTE: This assumes that the system is using ASCII ordering and
!> that this is therefore equal to LGE (lexical greater than/equal to).
INTERFACE OPERATOR(>=)
  !> @copybrief Strings::greaterthanequal_char_StringType
  !> @copydetails Strings::greaterthanequal_char_StringType
  MODULE PROCEDURE greaterthanequal_char_StringType
  !> @copybrief Strings::greaterthanequal_StringType_char
  !> @copydetails Strings::greaterthanequal_StringType_char
  MODULE PROCEDURE greaterthanequal_StringType_char
  !> @copybrief Strings::greaterthanequal_StringType_StringType
  !> @copydetails Strings::greaterthanequal_StringType_StringType
  MODULE PROCEDURE greaterthanequal_StringType_StringType
ENDINTERFACE
317
318
!
!===============================================================================
HendersonSC's avatar
HendersonSC committed
319
CONTAINS
320
321
322
323
324
325
326
327
328
!!
!!-------------------------------------------------------------------------------
!!> @brief cleans up string objects
!!> @param this the StringType being garbaged collected
!!>
!ELEMENTAL SUBROUTINE clean_str(this)
!  TYPE(StringType),INTENT(INOUT) :: this
!  IF(ALLOCATED(this%s)) DEALLOCATE(this%s)
!ENDSUBROUTINE clean_str
329
330
331
332
333
!
!-------------------------------------------------------------------------------
!> @brief cleans up string objects
!> @param this the StringType being garbaged collected
!>
334
335
336
337
SUBROUTINE clear_str(this)
  CLASS(StringType),INTENT(INOUT) :: this
  IF(ALLOCATED(this%s)) DEALLOCATE(this%s)
ENDSUBROUTINE clear_str
338
339
!
!-------------------------------------------------------------------------------
340
341
!> @brief breaks a string into partitions at the first instance of a delimiter
!> @param this the string being partitioned
342
343
344
!> @param sep the delimiter used for partitioning
!> @returns tokens size 3 array containing the characters before the delimiter,
!> the delimiter, and the characters after the delimiter in that order
345
!>
346
347
348
349
350
PURE FUNCTION partition(this,sep) RESULT(tokens)
  CLASS(StringType),INTENT(IN) :: this
  CHARACTER(LEN=*),INTENT(IN) :: sep
  TYPE(StringType) :: tokens(3)
  INTEGER(SIK) :: sepPos
351
352
353
354
355
356
357
358
359
360
  IF(ALLOCATED(this%s)) THEN
    sepPos = MERGE(0,INDEX(this%s,sep),sep == '')
    IF(sepPos > 0) THEN
      tokens(1) = this%s(1:sepPos-1)
      tokens(3) = this%s(sepPos+LEN(SEP):LEN(this%s))
    ELSE
      tokens(1) = this%s
      tokens(3) = ''
    ENDIF
    tokens(2) = sep
361
  ELSE
362
363
364
    tokens(1)=''
    tokens(2)=sep
    tokens(3)=''
365
366
367
368
369
370
  ENDIF
ENDFUNCTION partition
!
!-------------------------------------------------------------------------------
!> @brief breaks a string into partitions at the last instance of a delimiter
!> @param this the string being partitioned
371
372
373
!> @param sep the delimiter used for partitioning
!> @returns tokens size 3 array containing the characters before the delimiter,
!> the delimiter, and the characters after the delimiter in that order
374
375
376
377
378
379
!>
PURE FUNCTION rPartition(this,sep) RESULT(tokens)
  CLASS(StringType),INTENT(IN) :: this
  CHARACTER(LEN=*),INTENT(IN) :: sep
  TYPE(StringType) :: tokens(3)
  INTEGER(SIK) :: sepPos
380
381
382
383
384
385
386
387
388
389
  IF(ALLOCATED(this%s)) THEN
    sepPos = MERGE(0,INDEX(this%s,sep,.TRUE.),sep == '')
    IF(sepPos > 0) THEN
      tokens(1) = this%s(1:sepPos-1)
      tokens(3) = this%s(sepPos+LEN(SEP):LEN(this%s))
    ELSE
      tokens(1) = ''
      tokens(3) = this%s
    ENDIF
    tokens(2) = sep
390
  ELSE
391
392
393
    tokens(1)=''
    tokens(2)=sep
    tokens(3)=''
394
395
396
397
  ENDIF
ENDFUNCTION rPartition
!
!-------------------------------------------------------------------------------
398
399
400
401
!> @brief Assigns an intrinsic character array to a string
!> @param lhs the string type receiving the characters
!> @param rhs the character string that will be assigned
!>
HendersonSC's avatar
HendersonSC committed
402
403
404
405
406
407
408
409
ELEMENTAL SUBROUTINE assign_char_to_StringType(lhs,rhs)
  CLASS(StringType),INTENT(INOUT) :: lhs
  CHARACTER(LEN=*),INTENT(IN) :: rhs
  IF(ALLOCATED(lhs%s)) DEALLOCATE(lhs%s)
  IF(LEN(rhs)>0) THEN
    lhs%s = rhs
  ENDIF
ENDSUBROUTINE assign_char_to_StringType
410
411
412
413
!
!-------------------------------------------------------------------------------
!> @brief converts a c-style character array to an intrinsic Fortran array
!>
HendersonSC's avatar
HendersonSC committed
414
415
416
417
FUNCTION cchar_to_fchar(cchar) RESULT(fchar)
  CHARACTER(KIND=C_CHAR),TARGET,INTENT(IN) :: cchar(:)
  CHARACTER(LEN=:),ALLOCATABLE :: fchar
  INTEGER(SIK) :: i,n
418

HendersonSC's avatar
HendersonSC committed
419
420
421
422
423
424
  n = SIZE(cchar)
  ALLOCATE(CHARACTER(n) :: fchar)
  DO i=1,n
    fchar(i:i) = cchar(i)
  ENDDO
ENDFUNCTION cchar_to_fchar
425
426
!
!-------------------------------------------------------------------------------
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
!> @brief splits a StringType using a single space as the delimiter. This
!> routine consumes consecutive spaces as a if they were a single space. The
!> @param this the StringType being split
!> @returns sub_str an array of substings
!>
!> The returned array of strings will not contain any empty strings. If the
!> string being split is empty the returned array will be size 0. If there were
!> no separators found to split on the array will be size 1, and contain the
!> original string.
!>
FUNCTION split_string_space(this) RESULT(sub_str)
  CLASS(StringType),INTENT(IN) :: this
  TYPE(StringType),ALLOCATABLE :: sub_str(:)
  !
  INTEGER(SIK) :: iSplit,nSplits,stt,stp,sepLoc

443
444
445
446
447
448
449
450
451
  IF(ALLOCATED(this%s)) THEN
    stp = LEN(this%s)
    sepLoc = MERGE(INDEX(this%s,' '),0,stp > 1)
    IF(sepLoc == 0) THEN
      !This indicates that either the string or the separator were empty, or
      !the separator was not found in the string.
      ALLOCATE(sub_str(1))
      sub_str(1) = this%s
      RETURN !For these conditions the original string is returned
452
453
    ENDIF

454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
    ! Search until the delimiter isn't found
    nSplits = 0
    stt = 1
    DO WHILE(sepLoc > 0)
    ! If the index is greater than 1 then the first character must be a string
      IF(sepLoc > 1) THEN
        ! Count the string
        nSplits = nSplits + 1
      ENDIF
      ! Increment to the next delimiter
      stt = stt + sepLoc
      sepLoc = INDEX(this%s(stt:stp),' ')
    ENDDO
    !Account for strings that don't end in a delimiter
    IF(stt <= stp) nSplits = nSplits + 1
    ALLOCATE(sub_str(nSplits))

    ! Split along delimiters and store in the provided array
    stt = 1
    iSplit = 0
474
    sepLoc = INDEX(this%s(stt:stp),' ')
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
    DO WHILE(sepLoc > 0)
      IF(sepLoc > 1) THEN
        iSplit = iSplit + 1
        ! Strip out the string...subtract 2 (1 for exclusive, 1 for delimiter)
        sub_str(iSplit) = this%s(stt:stt+sepLoc-2)
      ENDIF
      stt = stt + sepLoc
      sepLoc = INDEX(this%s(stt:stp),' ')
    ENDDO
    ! If the string ends with a word, then it wasn't snatched out before
    IF(.NOT.(this%s(stp:stp) == ' ')) THEN
      sub_str(nSplits) = &
          this%s(INDEX(this%s(1:stp),' ',.TRUE.)+1:stp)
    ENDIF
  ELSE
    ALLOCATE(sub_str(1))
    sub_str=''
492
493
494
495
  ENDIF
ENDFUNCTION split_string_space
!
!-------------------------------------------------------------------------------
496
!> @brief splits a StringType at specified delimiter and returns the substrings
497
!> in an array of StringTypes.
498
!> @param this the string to be split
499
500
!> @param separator the delimiter for split locations
!> @returns sub_str the returned array of substrings
501
!>
HendersonSC's avatar
HendersonSC committed
502
503
FUNCTION split_string(this,separator) RESULT(sub_str)
  CLASS(StringType),INTENT(IN) :: this
Graham, Aaron's avatar
Graham, Aaron committed
504
  CHARACTER(LEN=*),INTENT(IN) :: separator
HendersonSC's avatar
HendersonSC committed
505
506
507
  TYPE(StringType),ALLOCATABLE :: sub_str(:)
  !
  INTEGER(SIK) :: iSplit,nSplits,stt,stp,sepLoc
508

509
510
511
512
513
514
515
516
517
518
  IF(ALLOCATED(this%s)) THEN
    stp = LEN(this%s)
    sepLoc = MERGE(INDEX(this%s,separator),0,stp > 1 .OR. LEN(separator) > 0)
    IF(sepLoc == 0) THEN
      !This indicates that either the string or the separator were empty, or
      !the separator was not found in the string.
      ALLOCATE(sub_str(1))
      sub_str(1) = this%s
      RETURN !For these conditions the original string is returned
    ENDIF
519

520
521
522
523
524
525
526
527
528
529
530
    ! Count the number of splits
    nSplits = 0
    stt = 1
    DO WHILE(sepLoc > 0)
      nSplits = nSplits + 1
      stt = stt + sepLoc + LEN(separator) - 1
      sepLoc = INDEX(this%s(stt:stp),separator)
    ENDDO
    !Account for strings that don't end in a delimiter
    IF(stt <= stp) nSplits = nSplits + 1
    ALLOCATE(sub_str(nSplits))
531

532
533
    stt = 1
    iSplit = 0
534
    sepLoc = INDEX(this%s(stt:stp),separator)
535
536
537
538
539
540
541
542
543
544
545
546
547
548
    DO WHILE(sepLoc > 0)
      iSplit = iSplit + 1
      sub_str(iSplit) = this%s(stt:stt+sepLoc-2)
      stt = stt + sepLoc + LEN(separator) - 1
      sepLoc = INDEX(this%s(stt:stp),separator)
    ENDDO
    ! If the string ends with a word, then it wasn't snatched out before
    IF(iSplit < nSplits) THEN
      sub_str(nSplits) = &
          this%s(INDEX(this%s(1:stp),separator,.TRUE.)+LEN(separator):stp)
    ENDIF
  ELSE
    ALLOCATE(sub_str(1))
    sub_str=''
HendersonSC's avatar
HendersonSC committed
549
550
  ENDIF
ENDFUNCTION split_string
551
552
!
!-------------------------------------------------------------------------------
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
!> @brief returns a copy of the string with every occurrence of a specified
!> search pattern with the designated replacement pattern.
!> @param this the StringType being operated on
!> @param oldPat the pattern being replaced
!> @param newPat the pattern being inserted
!> @returns retStr the newly formed string
!> This routine will automatically account for size changes of the underlying
!> character array. If the search pattern is not found, then the original string
!> is returned
!>
FUNCTION replace_pattern(this,oldPat,newPat) RESULT(retStr)
  CLASS(StringType),INTENT(IN) :: this
  CHARACTER(LEN=*),INTENT(IN) :: oldPat
  CHARACTER(LEN=*),INTENT(IN) :: newPat
  CHARACTER(LEN=:),ALLOCATABLE :: retStr
  !
  TYPE(StringType),ALLOCATABLE :: tokens(:)
  INTEGER(SIK) :: iToken

  !Split out the parts to be retained
  tokens = this%split(oldPat)

  !Set-up the new string
  IF(SIZE(tokens) > 1) THEN
    retStr = ''
  ELSE
    retStr = char(tokens(1))
    RETURN
  ENDIF

  DO iToken=1,SIZE(tokens)-1
    IF(tokens(iToken) == '') THEN
      retStr = retStr//newPat
    ELSE
      retStr = retStr//tokens(iToken)//newPat
    ENDIF
  ENDDO
  IF(tokens(SIZE(tokens)) /= '') THEN
    retStr = retStr//tokens(SIZE(tokens))
  ELSE
    retStr = retStr//newPat
  ENDIF
ENDFUNCTION replace_pattern
!
!-------------------------------------------------------------------------------
598
599
600
601
602
603
604
!> @brief replaces a slice from a string with the designated character(s). If
!> the replacement characters are not the same size as the slice, the characters
!> are repeated until the slice is filled, any excess is truncated
!> @param this the string where the substitution is occurring
!> @param stt the start of the slice to be replaced
!> @param stp the end of the slice to be replaced
!> @param in_char the characters that will be subbed in
605
!> @returns retStr the newly formed string
606
!>
HendersonSC's avatar
HendersonSC committed
607
608
609
610
611
612
613
614
615
FUNCTION replace_slice(this,stt,stp,in_char) RESULT(retStr)
  CLASS(StringType),INTENT(INOUT) :: this
  INTEGER(SIK),INTENT(IN) :: stt
  INTEGER(SIK),INTENT(IN) :: stp
  CHARACTER(LEN=*),INTENT(IN) :: in_char
  !
  CHARACTER(LEN=stp-stt+1) :: tmp_str
  INTEGER(SIK) :: full,part,step
  CHARACTER(LEN=:),ALLOCATABLE :: retStr
616

HendersonSC's avatar
HendersonSC committed
617
618
619
620
621
622
623
624
625
626
627
628
  IF((stt <= stp) .AND. (stt > 0) .AND. (stp <= LEN(this))) THEN
    ! Find the number of characters being replaced
    step = stp-stt+1
    ! Find the number of full replacement strings required
    full = LEN(in_char)/step
    ! Find the length of any partial replacements
    part = MOD(LEN(in_char),step)

    !Construct the replacement string
    tmp_str(1:step) = " "
    IF(full > 0) THEN
      tmp_str = REPEAT(in_char,full)
629
    ENDIF
HendersonSC's avatar
HendersonSC committed
630
631
632
633
634
635
636
637
638
639
640
    IF(part > 0) THEN
      tmp_str = TRIM(tmp_str)//in_char(1:part)
    ENDIF

    ! Direct substitution of characters
    retStr = this%s
    retStr(stt:stp) = tmp_str(1:step)
  ELSE
    retStr =this%s
  ENDIF
ENDFUNCTION replace_slice
641
642
643
644
645
646
!
!-------------------------------------------------------------------------------
!> @brief Returns the character at the index provided, if the index is out of
!> or the string is not allocated then the ascii null character is returned.
!> @param this the string being indexed into
!> @param pos the index the character should be taken from
647
!> @returns letter the character being returned
648
!>
HendersonSC's avatar
HendersonSC committed
649
650
651
652
PURE FUNCTION at_string(this,pos) RESULT(letter)
  CLASS(StringType),INTENT(IN) :: this
  INTEGER(SIK),INTENT(IN) :: pos
  CHARACTER(LEN=:),ALLOCATABLE :: letter
653

654
  IF(ALLOCATED(this%s) .AND. (pos > 0) .AND. (pos <= LEN(this))) THEN
HendersonSC's avatar
HendersonSC committed
655
656
657
658
659
    letter = this%s(pos:pos)
  ELSE
    ALLOCATE(CHARACTER(0) :: letter)
  ENDIF
ENDFUNCTION at_string
660
661
662
663
664
665
666
!
!-------------------------------------------------------------------------------
!> @brief Returns the characters in the slice indicated, if the either index is
!> out of range, then the ascii null character is returned
!> @param this the string being sliced
!> @param stt the first index of the slice
!> @param stp the last index of the slice OPTIONAL: Default = LEN(this)
667
!> @returns slice the character(s) being returned
668
!
HendersonSC's avatar
HendersonSC committed
669
670
671
672
673
674
PURE FUNCTION substr_str(this,stt,stp) RESULT(slice)
  CLASS(StringType),INTENT(IN) :: this
  INTEGER(SIK),INTENT(IN) :: stt
  INTEGER(SIK),INTENT(IN),OPTIONAL :: stp
  CHARACTER(LEN=:),ALLOCATABLE :: slice
  INTEGER(SIK) :: sub_stp
675

HendersonSC's avatar
HendersonSC committed
676
677
678
679
680
  IF(PRESENT(stp)) THEN
    sub_stp = stp
  ELSE
    sub_stp = LEN(this)
  ENDIF
681
  IF(ALLOCATED(this%s) .AND. (stt > 0) .AND. (sub_stp <= LEN(this))) THEN
HendersonSC's avatar
HendersonSC committed
682
683
684
685
686
    slice = this%s(stt:sub_stp)
  ELSE
    ALLOCATE(CHARACTER(0) :: slice)
  ENDIF
ENDFUNCTION substr_str
687
688
689
690
691
!
!-------------------------------------------------------------------------------
!> @brief Utility function takes a string and converts all upper case letters to
!> lower case letters.
!> @param word input is a string, output has all lower case letters
692
!> @lower_str the lower cased version of this
693
!>
HendersonSC's avatar
HendersonSC committed
694
695
696
697
698
699
700
701
PURE FUNCTION toLower_string(word) RESULT(lower_str)
  CLASS(StringType),INTENT(IN) :: word
  INTEGER(SIK) :: i
  !
  TYPE(StringType) :: lower_str
  lower_str = word
  DO i=1,LEN(word)
    IF('A' <= word%s(i:i) .AND. word%s(i:i) <= 'Z') &
Graham, Aaron's avatar
Graham, Aaron committed
702
        lower_str%s(i:i)=ACHAR(IACHAR(word%s(i:i))+32)
HendersonSC's avatar
HendersonSC committed
703
704
  ENDDO
ENDFUNCTION toLower_string
705
706
707
708
709
!
!-------------------------------------------------------------------------------
!> @brief Utility function takes a string and converts all lower case letters to
!> upper case letters.
!> @param word input is a string, output has all upper case letters
710
!> @upper_str the upper cased version of this
711
!>
HendersonSC's avatar
HendersonSC committed
712
713
714
715
716
717
718
719
PURE FUNCTION toupper_string(word) RESULT(upper_str)
  CLASS(StringType),INTENT(IN) :: word
  INTEGER(SIK) :: i
  !
  TYPE(StringType) :: upper_str
  upper_str = word
  DO i=1,LEN(word)
    IF('a' <= word%s(i:i) .AND. word%s(i:i) <= 'z') &
Graham, Aaron's avatar
Graham, Aaron committed
720
        upper_str%s(i:i)=ACHAR(IACHAR(word%s(i:i))-32)
HendersonSC's avatar
HendersonSC committed
721
722
  ENDDO
ENDFUNCTION toupper_string
723
724
!
!-------------------------------------------------------------------------------
725
!> @brief Returns the length of the string including all whitespace.
726
!> @param this the string object
727
728
!> @returns n the length of the string
!>
729
!> Should behave exactly as it would if called directly on a character array
HendersonSC's avatar
HendersonSC committed
730
731
732
ELEMENTAL FUNCTION LEN_StringType(this) RESULT(n)
  CLASS(StringType),INTENT(IN) :: this
  INTEGER(SIK) :: n
733
734
735
736
737
  IF(ALLOCATED(this%s)) THEN
    n=LEN(this%s)
  ELSE
    n = 0
  ENDIF
HendersonSC's avatar
HendersonSC committed
738
ENDFUNCTION LEN_StringType
739
740
!
!-------------------------------------------------------------------------------
741
!> @brief Returns the length of the string excluding trailing whitespace.
742
!> @param this the string object
743
744
!> @returns n the length of the string
!>
745
!> Should behave exactly as it would if called directly on a character array
HendersonSC's avatar
HendersonSC committed
746
747
748
749
750
751
752
753
754
ELEMENTAL FUNCTION LEN_TRIM_StringType(this) RESULT(n)
  CLASS(StringType),INTENT(IN) :: this
  INTEGER(SIK) :: n
  IF(ALLOCATED(this%s)) THEN
    n=LEN_TRIM(this%s)
  ELSE
    n=0
  ENDIF
ENDFUNCTION LEN_TRIM_StringType
755
756
757
!
!-------------------------------------------------------------------------------
!> @brief Returns the contents of the string as an intrinsic character type
758
759
760
761
!> variable. If the string is unallocated a zero-length character is returned
!> @param this the string object
!> @returns str the character type with the value of @c this
!>
HendersonSC's avatar
HendersonSC committed
762
763
764
765
766
767
768
769
770
PURE FUNCTION CHAR_StringType(this) RESULT(str)
  CLASS(StringType),INTENT(IN) :: this
  CHARACTER(LEN=:),ALLOCATABLE :: str
  IF(ALLOCATED(this%s)) THEN
    str = this%s
  ELSE
    ALLOCATE(CHARACTER(0) :: str)
  ENDIF
ENDFUNCTION CHAR_StringType
771
772
773
774
!
!-------------------------------------------------------------------------------
!> @brief Returns the contents of the string excluding all trailing whitespace
!> as an intrinsic character type variable.
775
!> @param this the string object
776
!> @returns str this trimmed of trailing whitespace
777
!>
HendersonSC's avatar
HendersonSC committed
778
779
780
781
782
783
784
785
786
PURE FUNCTION TRIM_StringType(this) RESULT(str)
  CLASS(StringType),INTENT(IN) :: this
  CHARACTER(LEN=:),ALLOCATABLE :: str
  IF(ALLOCATED(this%s)) THEN
    str = TRIM(this%s)
  ELSE
    ALLOCATE(CHARACTER(0) :: str)
  ENDIF
ENDFUNCTION TRIM_StringType
787
788
789
790
!
!-------------------------------------------------------------------------------
!> @brief Returns the contents of the string as an intrinsic character type
!> variable with all preceding whitespace moved to the end.
791
!> @param this the string object
792
!> @returns s left aligned version of this
793
!>
794
795
PURE FUNCTION ADJUSTL_StringType(this) RESULT(s)
  CLASS(StringType),INTENT(IN) :: this
HendersonSC's avatar
HendersonSC committed
796
  CHARACTER(LEN=:),ALLOCATABLE :: s
797
798
799
800
801
  IF(ALLOCATED(this%s)) THEN
    s = ADJUSTL(this%s)
  ELSE
    s = ''
  ENDIF
HendersonSC's avatar
HendersonSC committed
802
ENDFUNCTION ADJUSTL_StringType
803
804
805
806
!
!-------------------------------------------------------------------------------
!> @brief Returns the contents of the string as an intrinsic character type
!> variable with all trailing whitespace moved to the beginning.
807
!> @param this the string object
808
!> @returns s right aligned version of this
809
!>
810
811
PURE FUNCTION ADJUSTR_StringType(this) RESULT(s)
  CLASS(StringType),INTENT(IN) :: this
HendersonSC's avatar
HendersonSC committed
812
  CHARACTER(LEN=:),ALLOCATABLE :: s
813
814
815
816
817
  IF(ALLOCATED(this%s)) THEN
    s = ADJUSTR(this%s)
  ELSE
    s = ''
  ENDIF
HendersonSC's avatar
HendersonSC committed
818
ENDFUNCTION ADJUSTR_StringType
819
820
!
!-------------------------------------------------------------------------------
821
!> @brief Returns the starting position of a @c CHARACTER substring within a
822
823
824
825
826
827
828
!> @c StringType string.
!> @param string the @c StringType object in which @c substring is located
!> @param substring the @c CHARACTER string to locate within @c string
!> @param back a logical indicating whether or not to return the position of
!>        the first or last instance of the @c substring within @c string
!> @returns ipos the position in @c string of the @c substring
!>
HendersonSC's avatar
HendersonSC committed
829
830
831
832
833
ELEMENTAL FUNCTION INDEX_StringType_char(string,substring,back) RESULT(ipos)
  CLASS(StringType),INTENT(IN) :: string
  CHARACTER(LEN=*),INTENT(IN) :: substring
  LOGICAL,INTENT(IN),OPTIONAL :: back
  INTEGER :: ipos
834
835
836
837
838
  IF(ALLOCATED(string%s) .AND. LEN(substring) > 0) THEN
    ipos=INDEX(string%s,substring,back)
  ELSE
    ipos = 0
  ENDIF
HendersonSC's avatar
HendersonSC committed
839
ENDFUNCTION INDEX_StringType_char
840
841
!
!-------------------------------------------------------------------------------
842
!> @brief Returns the starting position of a @c StringType substring within a
843
844
845
846
847
848
849
!> @c CHARACTER string.
!> @param string the @c CHARACTER string in which @c substring is located
!> @param substring the @c StringType object to locate within @c string
!> @param back a logical indicating whether or not to return the position of
!>        the first or last instance of the @c substring within @c string
!> @returns ipos the position in @c string of the @c substring
!>
HendersonSC's avatar
HendersonSC committed
850
851
852
853
854
ELEMENTAL FUNCTION INDEX_char_StringType(string,substring,back) RESULT(ipos)
  CHARACTER(LEN=*),INTENT(IN) :: string
  CLASS(StringType),INTENT(IN) :: substring
  LOGICAL,INTENT(IN),OPTIONAL :: back
  INTEGER :: ipos
855
856
857
858
859
  IF(ALLOCATED(substring%s) .AND. LEN(string) > 0) THEN
    ipos=INDEX(string,substring%s,back)
  ELSE
    ipos = 0
  ENDIF
HendersonSC's avatar
HendersonSC committed
860
ENDFUNCTION INDEX_char_StringType
861
862
!
!-------------------------------------------------------------------------------
863
!> @brief Returns the starting position of a @c StringType substring within a
864
865
866
867
868
869
870
!> @c StringType string.
!> @param string the @c StringType object in which @c substring is located
!> @param substring the @c StringType object to locate within @c string
!> @param back a logical indicating whether or not to return the position of
!>        the first or last instance of the @c substring within @c string
!> @returns ipos the position in @c string of the @c substring
!>
HendersonSC's avatar
HendersonSC committed
871
872
873
874
875
ELEMENTAL FUNCTION INDEX_StringType_StringType(string,substring,back) RESULT(ipos)
  CLASS(StringType),INTENT(IN) :: string
  CLASS(StringType),INTENT(IN) :: substring
  LOGICAL,INTENT(IN),OPTIONAL :: back
  INTEGER :: ipos
876
877
878
879
880
  IF(ALLOCATED(string%s) .AND. ALLOCATED(substring%s)) THEN
    ipos=INDEX(string%s,substring%s,back)
  ELSE
    ipos = 0
  ENDIF
HendersonSC's avatar
HendersonSC committed
881
ENDFUNCTION INDEX_StringType_StringType
882
883
!
!-------------------------------------------------------------------------------
884
!> @brief Assigns a short integer to a StringType.
885
!> @param lhs the string object
886
!> @param rhs short integer
887
!>
HendersonSC's avatar
HendersonSC committed
888
889
890
891
892
893
894
ELEMENTAL SUBROUTINE assign_Short_Integer_to_StringType(lhs,rhs)
  CLASS(StringType),INTENT(INOUT) :: lhs
  INTEGER(SNK),INTENT(IN) :: rhs
  CHARACTER(LEN=11) :: l
  WRITE(l,'(i11)') rhs
  lhs = TRIM(ADJUSTL(l))
ENDSUBROUTINE assign_Short_Integer_to_StringType
895
896
897
!
!-------------------------------------------------------------------------------
!> @brief Assigns a long integer to a StringType.
898
899
!> @param lhs the string object
!> @param rhs long integer
900
!>
HendersonSC's avatar
HendersonSC committed
901
902
903
904
905
906
907
ELEMENTAL SUBROUTINE assign_Long_Integer_to_StringType(lhs,rhs)
  CLASS(StringType),INTENT(INOUT) ::lhs
  INTEGER(SLK),INTENT(IN) :: rhs
  CHARACTER(LEN=20) :: l
  WRITE(l,'(i20)') rhs
  lhs = TRIM(ADJUSTL(l))
ENDSUBROUTINE assign_Long_Integer_to_StringType
908
909
!
!-------------------------------------------------------------------------------
djabaay's avatar
djabaay committed
910
!> @brief Assigns a single real to a StringType.
911
!> @param lhs the string object
912
!> @param rhs single real
djabaay's avatar
djabaay committed
913
!>
HendersonSC's avatar
HendersonSC committed
914
915
916
917
918
919
920
ELEMENTAL SUBROUTINE assign_Single_Real_to_StringType(lhs,rhs)
  CLASS(StringType),INTENT(INOUT) :: lhs
  REAL(SSK),INTENT(IN) :: rhs
  CHARACTER(LEN=15) :: l
  WRITE(l,'(es15.5)') rhs
  lhs = TRIM(ADJUSTL(l))
ENDSUBROUTINE assign_Single_Real_to_StringType
djabaay's avatar
djabaay committed
921
922
923
!
!-------------------------------------------------------------------------------
!> @brief Assigns a double real to a StringType.
924
!> @param lhs the string object
925
!> @param rhs double real
djabaay's avatar
djabaay committed
926
!>
HendersonSC's avatar
HendersonSC committed
927
928
929
930
931
932
933
ELEMENTAL SUBROUTINE assign_Double_Real_to_StringType(lhs,rhs)
  CLASS(StringType),INTENT(INOUT) :: lhs
  REAL(SDK),INTENT(IN) :: rhs
  CHARACTER(LEN=22) :: l
  WRITE(l,'(es22.15)') rhs
  lhs = TRIM(ADJUSTL(l))
ENDSUBROUTINE assign_Double_Real_to_StringType
djabaay's avatar
djabaay committed
934
935
!
!-------------------------------------------------------------------------------
936
937
!> @brief Assigns a logical to a StringType.
!> @param lhs the string object
938
!> @param rhs the logical to be written
939
!>
HendersonSC's avatar
HendersonSC committed
940
941
942
943
944
945
946
SUBROUTINE assign_Logical_to_StringType(lhs,rhs)
  CLASS(StringType),INTENT(INOUT) :: lhs
  LOGICAL(SBK),INTENT(IN) :: rhs
  CHARACTER(LEN=1) :: tmp
  WRITE(tmp,'(L1)') rhs
  lhs = tmp
ENDSUBROUTINE assign_Logical_to_StringType
947
948
!
!-------------------------------------------------------------------------------
949
!> @brief Concatenates an intrinsic character type variable with a
950
951
952
!> @c StringType.
!> @param thisStr the string object
!> @param s the length of the string
953
954
!> @returns newstring a character string that is a concatenation of a
!> @c StringType and character string
955
!>
HendersonSC's avatar
HendersonSC committed
956
957
958
959
960
961
PURE FUNCTION concatenate_StringType_onto_char(lhs,rhs) RESULT(out_str)
  CHARACTER(LEN=*),INTENT(IN) :: lhs
  CLASS(StringType),INTENT(IN) :: rhs
  CHARACTER(LEN=:),ALLOCATABLE :: out_str
  out_str = (lhs//CHAR(rhs))
ENDFUNCTION concatenate_StringType_onto_char
962
963
!
!-------------------------------------------------------------------------------
964
!> @brief Concatenates an intrinsic character type variable with a
965
966
!> @c StringType.
!> @param s the length of the string
967
968
969
!> @param thisStr the string object
!> @returns newstring a character string that is a concatenation of a
!> @c StringType and character string
970
!>
HendersonSC's avatar
HendersonSC committed
971
972
973
974
975
976
PURE FUNCTION concatenate_char_onto_StringType(lhs,rhs) RESULT(out_str)
  CLASS(StringType),INTENT(IN) :: lhs
  CHARACTER(LEN=*),INTENT(IN) :: rhs
  CHARACTER(LEN=:),ALLOCATABLE :: out_str
  out_str = (CHAR(lhs)//rhs)
ENDFUNCTION concatenate_char_onto_StringType
977
978
!
!-------------------------------------------------------------------------------
979
980
981
982
983
!> @brief Concatenates a @c StringType type variable with a @c StringType.
!> @param s1 the string object
!> @param s2 the string object
!> @returns newstring a character string that is a concatenation of a
!> two @c StringTypes
984
!>
HendersonSC's avatar
HendersonSC committed
985
986
987
988
989
990
PURE FUNCTION concatenate_StringType_onto_StringType(lhs,rhs) RESULT(out_str)
  CLASS(StringType),INTENT(IN) :: lhs
  CLASS(StringType),INTENT(IN) :: rhs
  CHARACTER(LEN=:),ALLOCATABLE :: out_str
  out_str = (CHAR(lhs)//CHAR(rhs))
ENDFUNCTION concatenate_StringType_onto_StringType
991
992
993
994
!
!-------------------------------------------------------------------------------
!> @brief Performs an equal to operation of a @c CHARACTER and a
!> @c StringType.
995
996
!> @param lhs a @c CHARACTER type
!> @param rhs a @c StringType object
997
998
!> @returns bool the result of the == operation
!>
HendersonSC's avatar
HendersonSC committed
999
1000
ELEMENTAL FUNCTION equalto_char_StringType(lhs,rhs) RESULT(bool)
  CHARACTER(LEN=*),INTENT(IN) :: lhs
For faster browsing, not all history is shown. View entire blame