Strings.f90 25.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
!                              Copyright (C) 2012                              !
!                   The Regents of the University of Michigan                  !
!              MPACT Development Group and Prof. Thomas J. Downar              !
!                             All rights reserved.                             !
!                                                                              !
! Copyright is reserved to the University of Michigan for purposes of          !
! controlled dissemination, commercialization through formal licensing, or     !
! other disposition. The University of Michigan nor any of their employees,    !
! makes any warranty, express or implied, or assumes any liability or          !
! responsibility for the accuracy, completeness, or usefulness of any          !
! information, apparatus, product, or process disclosed, or represents that    !
! its use would not infringe privately owned rights. Reference herein to any   !
! specific commercial products, process, or service by trade name, trademark,  !
! manufacturer, or otherwise, does not necessarily constitute or imply its     !
! endorsement, recommendation, or favoring by the University of Michigan.      !
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
!> @brief Module for specifying a type for arbitrary length strings
!> 
20
!> This module defines a type for a string which can be an arbitrary length.
21
!> It then provides overloaded operators and intrinsic functions so
22
!> that it can be used almost exactly like a Fortran @c CHARACTER type variable.
23
!>
24
25
26
27
28
29
30
!> 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
31
!> @c StringType
32
33
34
35
36
!>  - @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
37
!>  - @c INDEX
38
39
40
!>
!> @par Module Dependencies
!>  - @ref IntrType "IntrType": @copybrief IntrType
41
42
43
44
45
46
47
!>
!> @par EXAMPLE
!> @code
!> PROGRAM
!>   USE Strings
!>   IMPLICIT NONE
!>   
48
49
50
!>   CHARACTER(LEN=20) :: char20
!>   TYPE(StringType) :: myString
!>
51
52
53
54
55
56
!>   WRITE(*,*) '"'//CHAR(myString)//'"'
!>   WRITE(*,*) '"'//TRIM(myString)//'"'
!>   WRITE(*,*) '"'//ADJUSTL(myString)//'"'
!>   WRITE(*,*) '"'//ADJUSTR(myString)//'"'
!>   WRITE(*,*) '"'//LEN(myString)//'"'
!>   WRITE(*,*) '"'//LEN_TRIM(myString)//'"'
57
58
59
!>
!>   myString=' hello world'
!>   char20=myString
60
!>   WRITE(*,*) '"'//CHAR(myString)//'"'
61
!>   WRITE(*,*) '"'//char20//'"'
62
!>   WRITE(*,*) '"'//TRIM(CHAR(myString))//'"'
63
!>   WRITE(*,*) '"'//TRIM(char20)//'"'
64
!>   WRITE(*,*) '"'//ADJUSTL(CHAR(myString))//'"'
65
!>   WRITE(*,*) '"'//ADJUSTL(char20)//'"'
66
!>   WRITE(*,*) '"'//ADJUSTR(myString)//'"'
67
!>   WRITE(*,*) '"'//ADJUSTR(char20)//'"'
68
!>   WRITE(*,*) '"'//LEN(myString)//'"'
69
!>   WRITE(*,*) '"'//LEN(char20)//'"'
70
!>   WRITE(*,*) '"'//LEN_TRIM(myString)//'"'
71
72
73
!>   WRITE(*,*) '"'//LEN_TRIM(char20)//'"'
!>
!>   myString=char20
74
!>   WRITE(*,*) '"'//CHAR(myString)//'"'
75
!>   WRITE(*,*) '"'//char20//'"'
76
!>   WRITE(*,*) '"'//TRIM(myString)//'"'
77
!>   WRITE(*,*) '"'//TRIM(char20)//'"'
78
!>   WRITE(*,*) '"'//ADJUSTL(myString)//'"'
79
!>   WRITE(*,*) '"'//ADJUSTL(char20)//'"'
80
!>   WRITE(*,*) '"'//ADJUSTR(myString)//'"'
81
!>   WRITE(*,*) '"'//ADJUSTR(char20)//'"'
82
!>   WRITE(*,*) '"'//LEN(myString)//'"'
83
!>   WRITE(*,*) '"'//LEN(char20)//'"'
84
!>   WRITE(*,*) '"'//LEN_TRIM(myString)//'"'
85
!>   WRITE(*,*) '"'//LEN_TRIM(char20)//'"'
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
!>
!> END PROGRAM
!> @endcode
!>
!> @author Brendan Kochunas
!>   @date 07/25/2012
!>
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
MODULE Strings
  
  USE IntrType
  IMPLICIT NONE
  PRIVATE !Default private for module contents
!
! List of Public items
  PUBLIC :: StringType
102
  PUBLIC :: CHAR
103
104
105
106
107
  PUBLIC :: LEN
  PUBLIC :: LEN_TRIM
  PUBLIC :: TRIM
  PUBLIC :: ADJUSTL
  PUBLIC :: ADJUSTR
108
  PUBLIC :: INDEX
109
110
111
112
  PUBLIC :: ASSIGNMENT(=)
  PUBLIC :: OPERATOR(//)
  PUBLIC :: OPERATOR(==)
  PUBLIC :: OPERATOR(/=)
113
114
115
  
  !> Derived type for an arbitrary length string
  TYPE :: StringType
116
117
118
119
    !> The size of the string
    !>
    !> This is needed because SIZE(%s) does not reliably return 0 when
    !> s has been allocated and then unallocated.
120
    INTEGER(SIK) :: n=0
121
122
123
    !> The trim length of the string
    !>
    !> This is needed for the TRIM routine
124
    INTEGER(SIK) :: ntrim=0
125
    !> The string stored as an array of length 1 character strings
126
    CHARACTER(LEN=1),ALLOCATABLE :: s(:)
127
  ENDTYPE StringType
128
  
129
130
131
132
133
134
135
136
  !> @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
  ENDINTERFACE
  
137
  !> @brief Overloads the Fortran intrinsic procedure LEN() so
138
139
140
141
142
143
144
  !> a string type argument may be passed.
  INTERFACE LEN
    !> @copybrief Strings::LEN_StringType
    !> @copydetails Strings::LEN_StringType
    MODULE PROCEDURE LEN_StringType
  ENDINTERFACE
  
145
  !> @brief Overloads the Fortran intrinsic procedure LEN_TRIM() so
146
147
148
149
150
151
152
  !> 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
  
153
  !> @brief Overloads the Fortran intrinsic procedure TRIM() so
154
155
156
157
158
159
160
  !> a string type argument may be passed.
  INTERFACE TRIM
    !> @copybrief Strings::TRIM_StringType
    !> @copydetails Strings::TRIM_StringType
    MODULE PROCEDURE TRIM_StringType
  ENDINTERFACE
  
161
  !> @brief Overloads the Fortran intrinsic procedure ADJUSTL() so 
162
163
164
165
166
167
168
  !> a string type argument may be passed.
  INTERFACE ADJUSTL
    !> @copybrief Strings::ADJUSTL_StringType
    !> @copydetails Strings::ADJUSTL_StringType
    MODULE PROCEDURE ADJUSTL_StringType
  ENDINTERFACE
  
169
  !> @brief Overloads the Fortran intrinsic procedure ADJUSTR() so 
170
171
172
173
174
175
  !> a string type argument may be passed.
  INTERFACE ADJUSTR
    !> @copybrief Strings::ADJUSTR_StringType
    !> @copydetails Strings::ADJUSTR_StringType
    MODULE PROCEDURE ADJUSTR_StringType
  ENDINTERFACE
176
  
177
178
179
180
181
182
183
184
185
186
187
188
189
190
  !> @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
  
191
192
193
194
195
196
197
198
199
200
  !> @brief Overloads the assignment operator.
  !>
  !> This is so string types can be assigned to characters and vice-versa
  INTERFACE ASSIGNMENT(=)
    !> @copybrief Strings::assign_char_to_StringType
    !> @copydetails Strings::assign_char_to_StringType
    MODULE PROCEDURE assign_char_to_StringType
    !> @copybrief Strings::assign_StringType_to_char
    !> @copydetails Strings::assign_StringType_to_char
    MODULE PROCEDURE assign_StringType_to_char
201
202
203
    !> @copybrief Strings::assign_StringType_to_StringType
    !> @copydetails Strings::assign_StringType_to_StringType
    MODULE PROCEDURE assign_StringType_to_StringType
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
  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
247
248
249
250
251
!
!===============================================================================
  CONTAINS
!
!-------------------------------------------------------------------------------
252
253
254
255
256
257
258
259
!> @brief Returns the length of the string including all whitespace.
!> @param thisStr the string object
!> @returns n the length of the string
!>
!> The intent is that this behaves exactly the same way as the intrinsic
!> function @c LEN does for character variables.
!>
    ELEMENTAL FUNCTION LEN_StringType(thisStr) RESULT(n)
260
261
      CLASS(StringType),INTENT(IN) :: thisStr
      INTEGER(SIK) :: n
262
263
      n=thisStr%n
    ENDFUNCTION LEN_StringType
264
265
!
!-------------------------------------------------------------------------------
266
267
268
269
270
271
272
273
!> @brief Returns the length of the string excluding trailing whitespace.
!> @param thisStr the string object
!> @returns n the length of the string
!>
!> The intent is that this behaves exactly the same way as the intrinsic
!> function @c LEN_TRIM does for character variables.
!>
    ELEMENTAL FUNCTION LEN_TRIM_StringType(thisStr) RESULT(n)
274
      CLASS(StringType),INTENT(IN) :: thisStr
275
276
277
278
279
280
281
282
283
284
285
286
      INTEGER(SIK) :: n
      n=thisStr%ntrim
    ENDFUNCTION LEN_TRIM_StringType
!
!-------------------------------------------------------------------------------
!> @brief Returns the contents of the string as an intrinsic character type
!> variable.
!> @param thisStr the string object
!> @returns s the character type with the value of @c thisStr
!>
!> This routine basically converts a @c StringType to a @c CHARACTER type.
!>
287
    PURE FUNCTION CHAR_StringType(thisStr,stt,stp) RESULT(s)
288
      CLASS(StringType),INTENT(IN) :: thisStr
289
290
      INTEGER(SIK),INTENT(IN),OPTIONAL :: stt
      INTEGER(SIK),INTENT(IN),OPTIONAL :: stp
291
      CHARACTER(LEN=thisStr%n) :: s
292
      INTEGER(SIK) :: i,istt,istp,j
293
294
      s=''
      IF(thisStr%n > 0) THEN
295
296
297
298
299
300
301
302
        istt=1
        IF(PRESENT(stt)) istt=MAX(1,stt)
        istp=thisStr%n
        IF(PRESENT(stp)) istp=MIN(thisStr%n,stp)
        j=0
        DO i=istt,istp
          j=j+1
          s(j:j)=thisStr%s(i)
303
304
        ENDDO
      ENDIF
305
    ENDFUNCTION CHAR_StringType
306
307
308
309
310
311
312
313
314
315
316
317
318
!
!-------------------------------------------------------------------------------
!> @brief Returns the contents of the string excluding all trailing whitespace
!> as an intrinsic character type variable.
!> @param thisStr the string object
!> @returns s the character string
!>
!> The intent is that this behaves exactly the same way as the intrinsic
!> function @c TRIM does for character variables.
!>
    PURE FUNCTION TRIM_StringType(thisStr) RESULT(s)
      CLASS(StringType),INTENT(IN) :: thisStr
      CHARACTER(LEN=thisStr%ntrim) :: s
319
      INTEGER(SIK) :: i
320
      s=''
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
      IF(thisStr%ntrim > 0) THEN
        DO i=1,thisStr%ntrim
          s(i:i)=thisStr%s(i)
        ENDDO
      ENDIF
    ENDFUNCTION TRIM_StringType
!
!-------------------------------------------------------------------------------
!> @brief Returns the contents of the string as an intrinsic character type
!> variable with all preceding whitespace moved to the end.
!> @param thisStr the string object
!> @returns s the character string
!>
!> The intent is that this behaves exactly the same way as the intrinsic
!> function @c ADJUSTL does for character variables.
!>
    PURE FUNCTION ADJUSTL_StringType(thisStr) RESULT(s)
      CLASS(StringType),INTENT(IN) :: thisStr
      CHARACTER(LEN=thisStr%n) :: s
340
      s=ADJUSTL(CHAR(thisStr))
341
342
343
344
345
346
347
348
349
350
351
352
353
354
    ENDFUNCTION ADJUSTL_StringType
!
!-------------------------------------------------------------------------------
!> @brief Returns the contents of the string as an intrinsic character type
!> variable with all trailing whitespace moved to the beginning.
!> @param thisStr the string object
!> @returns s the character string
!>
!> The intent is that this behaves exactly the same way as the intrinsic
!> function @c ADJUSTR does for character variables.
!>
    PURE FUNCTION ADJUSTR_StringType(thisStr) RESULT(s)
      CLASS(StringType),INTENT(IN) :: thisStr
      CHARACTER(LEN=thisStr%n) :: s
355
      s=ADJUSTR(CHAR(thisStr))
356
    ENDFUNCTION ADJUSTR_StringType
357
358
!
!-------------------------------------------------------------------------------
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
!> @brief Returns the starting position of a @c CHARACTER substring within a 
!> @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
!>
!> The intent is that this behaves exactly the same way as the intrinsic
!> function @c INDEX does for character variables.
!>
    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
      IF(PRESENT(back)) THEN
376
        ipos=INDEX(CHAR(string),substring,back)
377
      ELSE
378
        ipos=INDEX(CHAR(string),substring)
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
      ENDIF
    ENDFUNCTION INDEX_StringType_char
!
!-------------------------------------------------------------------------------
!> @brief Returns the starting position of a @c StringType substring within a 
!> @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
!>
!> The intent is that this behaves exactly the same way as the intrinsic
!> function @c INDEX does for character variables.
!>
    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
      IF(PRESENT(back)) THEN
400
        ipos=INDEX(string,CHAR(substring),back)
401
      ELSE
402
        ipos=INDEX(string,CHAR(substring))
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
      ENDIF
    ENDFUNCTION INDEX_char_StringType
!
!-------------------------------------------------------------------------------
!> @brief Returns the starting position of a @c StringType substring within a 
!> @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
!>
!> The intent is that this behaves exactly the same way as the intrinsic
!> function @c INDEX does for character variables.
!>
    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
      IF(PRESENT(back)) THEN
424
        ipos=INDEX(CHAR(string),CHAR(substring),back)
425
      ELSE
426
        ipos=INDEX(CHAR(string),CHAR(substring))
427
428
429
430
      ENDIF
    ENDFUNCTION INDEX_StringType_StringType
!
!-------------------------------------------------------------------------------
431
432
!> @brief Assigns the contents of a string to an intrinsic character type
!> variable.
433
!> @param s the character string
434
435
436
437
438
!> @param thisStr the string object
!>
!> The intent is that this will overload the assignment operator so a
!> @c StringType can be assigned to a @c CHARACTER type.
!>
439
440
441
    PURE SUBROUTINE assign_StringType_to_char(s,thisStr)
      CHARACTER(LEN=*),INTENT(INOUT) :: s  
      CLASS(StringType),INTENT(IN) :: thisStr
442
      s=CHAR(thisStr)
443
444
445
    ENDSUBROUTINE assign_StringType_to_char
!
!-------------------------------------------------------------------------------
446
447
448
!> @brief Assigns the contents of an intrinsic character type variable to a
!> @c StringType.
!> @param thisStr the string object
449
!> @param s the character string
450
451
452
453
!>
!> The intent is that this will overload the assignment operator so a
!> @c CHARACTER type can be assigned to a @c StringType.
!>
454
455
456
457
458
    PURE SUBROUTINE assign_char_to_StringType(thisStr,s)
      CLASS(StringType),INTENT(INOUT) :: thisStr
      CHARACTER(LEN=*),INTENT(IN) :: s
      INTEGER(SIK) :: i
      
459
      IF(thisStr%n > 0) THEN
460
        IF(ALLOCATED(thisStr%s)) DEALLOCATE(thisStr%s)
461
462
463
464
465
466
467
468
469
470
471
472
        thisStr%n=0
        thisStr%ntrim=0
      ENDIF
      
      IF(LEN(s) > 0) THEN
        thisStr%n=LEN(s)
        thisStr%ntrim=LEN_TRIM(s)
        ALLOCATE(thisStr%s(thisStr%n))
        DO i=1,thisStr%n
          thisStr%s(i)=s(i:i)
        ENDDO
      ENDIF
473
474
    ENDSUBROUTINE assign_char_to_StringType
!
475
!-------------------------------------------------------------------------------
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
!> @brief Assigns the contents of a @c StringType variable to a @c StringType.
!> @param thisStr the string object
!> @param s another string object
!>
!> The intent is that this will overload the assignment operator so a
!> @c Stringtype can be assigned to a @c StringType. This is used instead
!> of the intrinsic operation because I think there are some issues with
!> the allocatable component.
!>
    PURE SUBROUTINE assign_StringType_to_StringType(thisStr,s)
      CLASS(StringType),INTENT(INOUT) :: thisStr
      CLASS(StringType),INTENT(IN) :: s
      INTEGER(SIK) :: i
      
      IF(thisStr%n > 0) THEN
        DEALLOCATE(thisStr%s)
        thisStr%n=0
        thisStr%ntrim=0
      ENDIF
      
      IF(s%n > 0) THEN
        thisStr%n=s%n
        thisStr%ntrim=s%ntrim
        ALLOCATE(thisStr%s(thisStr%n))
        DO i=1,thisStr%n
          thisStr%s(i)=s%s(i)
        ENDDO
      ENDIF
    ENDSUBROUTINE assign_StringType_to_StringType
!
!-------------------------------------------------------------------------------
!> @brief Concatenates an intrinsic character type variable with a
508
509
510
!> @c StringType.
!> @param thisStr the string object
!> @param s the length of the string
511
512
!> @returns newstring a character string that is a concatenation of a
!> @c StringType and character string
513
!>
514
515
!> The intent is that this will overload the // operator so a
!> @c CHARACTER type can be concatenated with a @c StringType.
516
517
518
519
520
!>
    PURE FUNCTION concatenate_StringType_onto_char(s,thisStr) RESULT(newstring)
      CHARACTER(LEN=*),INTENT(IN) :: s  
      CLASS(StringType),INTENT(IN) :: thisStr
      CHARACTER(LEN=thisStr%n+LEN(s)) :: newstring
521
      newstring=s//CHAR(thisStr)
522
523
524
    ENDFUNCTION concatenate_StringType_onto_char
!
!-------------------------------------------------------------------------------
525
!> @brief Concatenates an intrinsic character type variable with a
526
527
!> @c StringType.
!> @param s the length of the string
528
529
530
!> @param thisStr the string object
!> @returns newstring a character string that is a concatenation of a
!> @c StringType and character string
531
!>
532
533
!> The intent is that this will overload the // operator so a
!> @c CHARACTER type can be concatenated with a @c StringType.
534
535
536
537
538
!>
    PURE FUNCTION concatenate_char_onto_StringType(thisStr,s) RESULT(newstring)
      CLASS(StringType),INTENT(IN) :: thisStr
      CHARACTER(LEN=*),INTENT(IN) :: s
      CHARACTER(LEN=thisStr%n+LEN(s)) :: newstring
539
      newstring=CHAR(thisStr)//s
540
541
542
    ENDFUNCTION concatenate_char_onto_StringType
!
!-------------------------------------------------------------------------------
543
544
545
546
547
548
549
550
!> @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
!>
!> The intent is that this will overload the // operator so a
!> @c StringType can be concatenated with a @c StringType.
551
552
553
554
555
!>
    PURE FUNCTION concatenate_StringType_onto_StringType(s1,s2) RESULT(s)
      CLASS(StringType),INTENT(IN) :: s1
      CLASS(StringType),INTENT(IN) :: s2
      CHARACTER(LEN=s1%n+s2%n) :: s
556
      s=CHAR(s1)//CHAR(s2)
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
    ENDFUNCTION concatenate_StringType_onto_StringType
!
!-------------------------------------------------------------------------------
!> @brief Performs an equal to operation of a @c CHARACTER and a
!> @c StringType.
!> @param s a @c CHARACTER type
!> @param thisStr a @c StringType object
!> @returns bool the result of the == operation
!>
!> The intent is that this will overload the == operator so a
!> @c CHARACTER type can compared with a @c StringType.
!>
    PURE FUNCTION equalto_char_StringType(s,thisStr) RESULT(bool)
      CHARACTER(LEN=*),INTENT(IN) :: s
      CLASS(StringType),INTENT(IN) :: thisStr
      LOGICAL(SBK) :: bool
573
      bool=(s == CHAR(thisStr))
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
    ENDFUNCTION equalto_char_StringType
!
!-------------------------------------------------------------------------------
!> @brief Performs an equal to operation of a @c CHARACTER and a
!> @c StringType.
!> @param thisStr a @c StringType object
!> @param s a @c CHARACTER type
!> @returns bool the result of the == operation
!>
!> The intent is that this will overload the == operator so a
!> @c CHARACTER type can compared with a @c StringType.
!>
    PURE FUNCTION equalto_StringType_char(thisStr,s) RESULT(bool)
      CLASS(StringType),INTENT(IN) :: thisStr
      CHARACTER(LEN=*),INTENT(IN) :: s
      LOGICAL(SBK) :: bool
590
      bool=(s == CHAR(thisStr))
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
    ENDFUNCTION equalto_StringType_char
!
!-------------------------------------------------------------------------------
!> @brief Performs an equal to operation of a @c StringType and a
!> @c StringType.
!> @param s1 a @c StringType object
!> @param s2 another @c StringType object
!> @returns bool the result of the == operation
!>
!> The intent is that this will overload the == operator so a
!> @c StringType type can compared with a @c StringType.
!>
    PURE FUNCTION equalto_StringType_StringType(s1,s2) RESULT(bool)
      CLASS(StringType),INTENT(IN) :: s1
      CLASS(StringType),INTENT(IN) :: s2
      LOGICAL(SBK) :: bool
607
      bool=(CHAR(s1) == CHAR(s2))
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
    ENDFUNCTION equalto_StringType_StringType
!
!-------------------------------------------------------------------------------
!> @brief Performs a not equal to operation of a @c CHARACTER and a
!> @c StringType.
!> @param s a @c CHARACTER type
!> @param thisStr a @c StringType object
!> @returns bool the result of the /= operation
!>
!> The intent is that this will overload the /= operator so a
!> @c CHARACTER type can compared with a @c StringType.
!>
    PURE FUNCTION notequalto_char_StringType(s,thisStr) RESULT(bool)
      CHARACTER(LEN=*),INTENT(IN) :: s
      CLASS(StringType),INTENT(IN) :: thisStr
      LOGICAL(SBK) :: bool
624
      bool=(s /= CHAR(thisStr))
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
    ENDFUNCTION notequalto_char_StringType
!
!-------------------------------------------------------------------------------
!> @brief Performs a not equal to operation of a @c CHARACTER and a
!> @c StringType.
!> @param thisStr a @c StringType object
!> @param s a @c CHARACTER type
!> @returns bool the result of the /= operation
!>
!> The intent is that this will overload the /= operator so a
!> @c CHARACTER type can compared with a @c StringType.
!>
    PURE FUNCTION notequalto_StringType_char(thisStr,s) RESULT(bool)
      CLASS(StringType),INTENT(IN) :: thisStr
      CHARACTER(LEN=*),INTENT(IN) :: s
      LOGICAL(SBK) :: bool
641
      bool=(s /= CHAR(thisStr))
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
    ENDFUNCTION notequalto_StringType_char
!
!-------------------------------------------------------------------------------
!> @brief Performs a not equal to operation of a @c StringType and a
!> @c StringType.
!> @param s1 a @c StringType object
!> @param s2 another @c StringType object
!> @returns bool the result of the /= operation
!>
!> The intent is that this will overload the /= operator so a
!> @c StringType type can compared with a @c StringType.
!>
    PURE FUNCTION notequalto_StringType_StringType(s1,s2) RESULT(bool)
      CLASS(StringType),INTENT(IN) :: s1
      CLASS(StringType),INTENT(IN) :: s2
      LOGICAL(SBK) :: bool
658
      bool=(CHAR(s1) /= CHAR(s2))
659
660
    ENDFUNCTION notequalto_StringType_StringType
!
661
ENDMODULE Strings