forked from fortran-lang/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdlib_string_type.fypp
1249 lines (967 loc) · 44 KB
/
stdlib_string_type.fypp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
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
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
! SPDX-Identifier: MIT
#:include "common.fypp"
!> Implementation of a string type to hold an arbitrary sequence of characters.
!>
!> This module provides string type compatible with all Fortran instrinsic character
!> procedures as well as overloaded operators for working with character variables.
!>
!> A string type can be easily constructed by creating a new instance from a
!> character variable or literal by invoking its constructor or by assigning it
!> to a string type. Generally, the string type behaves similar to a deferred
!> length character in most regards but adds memory access safety.
!>
!> The specification of this module is available [here](../page/specs/stdlib_string_type.html).
module stdlib_string_type
use stdlib_ascii, only: to_lower_ => to_lower, to_upper_ => to_upper, &
& to_title_ => to_title, to_sentence_ => to_sentence, reverse_ => reverse
use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool
use stdlib_optval, only: optval
implicit none
private
public :: string_type
public :: len, len_trim, trim, index, scan, verify, repeat, adjustr, adjustl
public :: lgt, lge, llt, lle, char, ichar, iachar
public :: to_lower, to_upper, to_title, to_sentence, reverse, move
public :: assignment(=)
public :: operator(>), operator(>=), operator(<), operator(<=)
public :: operator(==), operator(/=), operator(//)
public :: write(formatted), write(unformatted)
public :: read(formatted), read(unformatted)
integer, parameter :: long = selected_int_kind(18)
!> String type holding an arbitrary sequence of characters.
type :: string_type
! Use the sequence statement below as a hack to prevent extending this type.
! It is not used for storage association.
sequence
private
character(len=:), allocatable :: raw
end type string_type
!> Returns the length of the character sequence represented by the string.
!>
!> This method is elemental and returns a default integer scalar value.
interface len
module procedure :: len_string
end interface len
!> Constructor for new string instances
interface string_type
elemental module function new_string(string) result(new)
character(len=*), intent(in), optional :: string
type(string_type) :: new
end function new_string
#:for kind in INT_KINDS
elemental module function new_string_from_integer_${kind}$(val) result(new)
integer(${kind}$), intent(in) :: val
type(string_type) :: new
end function new_string_from_integer_${kind}$
#:endfor
#:for kind in LOG_KINDS
elemental module function new_string_from_logical_${kind}$(val) result(new)
logical(${kind}$), intent(in) :: val
type(string_type) :: new
end function new_string_from_logical_${kind}$
#:endfor
end interface string_type
!> Returns the length of the character sequence without trailing spaces
!> represented by the string.
!>
!> This method is elemental and returns a default integer scalar value.
interface len_trim
module procedure :: len_trim_string
end interface len_trim
!> Returns the character sequence hold by the string without trailing spaces.
!>
!> This method is elemental and returns a scalar character value.
interface trim
module procedure :: trim_string
end interface trim
!> Left-adjust the character sequence represented by the string.
!> The length of the character sequence remains unchanged.
!>
!> This method is elemental and returns a scalar character value.
interface adjustl
module procedure :: adjustl_string
end interface adjustl
!> Right-adjust the character sequence represented by the string.
!> The length of the character sequence remains unchanged.
!>
!> This method is elemental and returns a scalar character value.
interface adjustr
module procedure :: adjustr_string
end interface adjustr
!> Repeats the character sequence hold by the string by the number of
!> specified copies.
!>
!> This method is elemental and returns a scalar character value.
interface repeat
module procedure :: repeat_string
end interface repeat
!> Returns the lowercase version of the character sequence hold by the input string
!>
!> This method is Elemental and returns a new string_type instance which holds this
!> lowercase character sequence
interface to_lower
module procedure :: to_lower_string
end interface to_lower
!> Returns the uppercase version of the character sequence hold by the input string
!>
!> This method is Elemental and returns a new string_type instance which holds this
!> uppercase character sequence
interface to_upper
module procedure :: to_upper_string
end interface to_upper
!> Returns the titlecase version of the character sequence hold by the input string
!>
!> This method is Elemental and returns a new string_type instance which holds this
!> titlecase character sequence
interface to_title
module procedure :: to_title_string
end interface to_title
!> Returns the sentencecase version of the character sequence hold by the input string
!>
!> This method is elemental and returns a new string_type instance which holds this
!> sentencecase character sequence
interface to_sentence
module procedure :: to_sentence_string
end interface to_sentence
!> Reverses the character sequence hold by the input string
!>
!> This method is elemental and returns a new string_type instance which holds this
!> reverse character sequence
interface reverse
module procedure :: reverse_string
end interface reverse
!> Return the character sequence represented by the string.
!>
!> This method is elemental and returns a scalar character value.
interface char
module procedure :: char_string
module procedure :: char_string_pos
module procedure :: char_string_range
end interface char
!> Character-to-integer conversion function.
!>
!> This method is elemental and returns a default integer scalar value.
interface ichar
module procedure :: ichar_string
end interface ichar
!> Code in ASCII collating sequence.
!>
!> This method is elemental and returns a default integer scalar value.
interface iachar
module procedure :: iachar_string
end interface iachar
!> Position of a *substring* within a *string*.
!>
!> Returns the position of the start of the leftmost or rightmost occurrence
!> of string *substring* in *string*, counting from one. If *substring* is not
!> present in *string*, zero is returned.
!>
!> This method is elemental and returns a default integer scalar value.
interface index
module procedure :: index_string_string
module procedure :: index_string_char
module procedure :: index_char_string
end interface index
!> Scan a *string* for the presence of a *set* of characters. Scans a *string* for
!> any of the characters in a *set* of characters.
!>
!> If *back* is either absent or *false*, this function returns the position
!> of the leftmost character of *string* that is in *set*. If *back* is *true*,
!> the rightmost position is returned. If no character of *set* is found in
!> *string*, the result is zero.
!>
!> This method is elemental and returns a default integer scalar value.
interface scan
module procedure :: scan_string_string
module procedure :: scan_string_char
module procedure :: scan_char_string
end interface scan
!> Scan a string for the absence of a set of characters. Verifies that all
!> the characters in string belong to the set of characters in set.
!>
!> If *back* is either absent or *false*, this function returns the position
!> of the leftmost character of *string* that is not in *set*. If *back* is *true*,
!> the rightmost position is returned. If all characters of *string* are found
!> in *set*, the result is zero.
!>
!> This method is elemental and returns a default integer scalar value.
interface verify
module procedure :: verify_string_string
module procedure :: verify_string_char
module procedure :: verify_char_string
end interface verify
!> Version: experimental
!>
!> Moves the allocated character scalar from 'from' to 'to'
!> [Specifications](../page/specs/stdlib_string_type.html#move)
interface move
module procedure :: move_string_string
module procedure :: move_string_char
module procedure :: move_char_string
module procedure :: move_char_char
end interface move
!> Lexically compare the order of two character sequences being greater,
!> The left-hand side, the right-hand side or both character sequences can
!> be represented by a string.
!>
!> This method is elemental and returns a default logical scalar value.
interface lgt
module procedure :: lgt_string_string
module procedure :: lgt_string_char
module procedure :: lgt_char_string
end interface lgt
!> Lexically compare the order of two character sequences being less,
!> The left-hand side, the right-hand side or both character sequences can
!> be represented by a string.
!>
!> This method is elemental and returns a default logical scalar value.
interface llt
module procedure :: llt_string_string
module procedure :: llt_string_char
module procedure :: llt_char_string
end interface llt
!> Lexically compare the order of two character sequences being greater equal,
!> The left-hand side, the right-hand side or both character sequences can
!> be represented by a string.
!>
!> This method is elemental and returns a default logical scalar value.
interface lge
module procedure :: lge_string_string
module procedure :: lge_string_char
module procedure :: lge_char_string
end interface lge
!> Lexically compare the order of two character sequences being less equal,
!> The left-hand side, the right-hand side or both character sequences can
!> be represented by a string.
!>
!> This method is elemental and returns a default logical scalar value.
interface lle
module procedure :: lle_string_string
module procedure :: lle_string_char
module procedure :: lle_char_string
end interface lle
!> Assign a character sequence to a string.
interface assignment(=)
module procedure :: assign_string_char
end interface assignment(=)
!> Compare two character sequences for being greater, the left-hand side,
!> the right-hand side or both character sequences can be represented by
!> a string.
!>
!> This operator is elemental and returns a default logical scalar value.
interface operator(>)
module procedure :: gt_string_string
module procedure :: gt_string_char
module procedure :: gt_char_string
end interface operator(>)
!> Compare two character sequences for being less, the left-hand side,
!> the right-hand side or both character sequences can be represented by
!> a string.
!>
!> This operator is elemental and returns a default logical scalar value.
interface operator(<)
module procedure :: lt_string_string
module procedure :: lt_string_char
module procedure :: lt_char_string
end interface operator(<)
!> Compare two character sequences for being greater than, the left-hand side,
!> the right-hand side or both character sequences can be represented by
!> a string.
!>
!> This operator is elemental and returns a default logical scalar value.
interface operator(>=)
module procedure :: ge_string_string
module procedure :: ge_string_char
module procedure :: ge_char_string
end interface operator(>=)
!> Compare two character sequences for being less than, the left-hand side,
!> the right-hand side or both character sequences can be represented by
!> a string.
!>
!> This operator is elemental and returns a default logical scalar value.
interface operator(<=)
module procedure :: le_string_string
module procedure :: le_string_char
module procedure :: le_char_string
end interface operator(<=)
!> Compare two character sequences for equality, the left-hand side,
!> the right-hand side or both character sequences can be represented by
!> a string.
!>
!> This operator is elemental and returns a default logical scalar value.
interface operator(==)
module procedure :: eq_string_string
module procedure :: eq_string_char
module procedure :: eq_char_string
end interface operator(==)
!> Compare two character sequences for inequality, the left-hand side,
!> the right-hand side or both character sequences can be represented by
!> a string.
!>
!> This operator is elemental and returns a default logical scalar value.
interface operator(/=)
module procedure :: ne_string_string
module procedure :: ne_string_char
module procedure :: ne_char_string
end interface operator(/=)
!> Concatenate two character sequences, the left-hand side, the right-hand side
!> or both character sequences can be represented by a string.
!>
!> This operator is elemental and returns a scalar character value.
interface operator(//)
module procedure :: concat_string_string
module procedure :: concat_string_char
module procedure :: concat_char_string
end interface operator(//)
!> Write the character sequence hold by the string to a connected formatted
!> unit.
interface write(formatted)
module procedure :: write_formatted
end interface
!> Write the character sequence hold by the string to a connected unformatted
!> unit.
interface write(unformatted)
module procedure :: write_unformatted
end interface
!> Read a character sequence from a connected unformatted unit into the string.
interface read(formatted)
module procedure :: read_formatted
end interface
!> Read a character sequence from a connected unformatted unit into the string.
interface read(unformatted)
module procedure :: read_unformatted
end interface
contains
!> Assign a character sequence to a string.
elemental subroutine assign_string_char(lhs, rhs)
type(string_type), intent(inout) :: lhs
character(len=*), intent(in) :: rhs
lhs%raw = rhs
end subroutine assign_string_char
!> Returns the length of the character sequence represented by the string.
elemental function len_string(string) result(length)
type(string_type), intent(in) :: string
integer :: length
if (allocated(string%raw)) then
length = len(string%raw)
else
length = 0
end if
end function len_string
!> Returns the length of the character sequence without trailing spaces
!> represented by the string.
elemental function len_trim_string(string) result(length)
type(string_type), intent(in) :: string
integer :: length
length = merge(len_trim(string%raw), 0, allocated(string%raw))
end function len_trim_string
!> Character-to-integer conversion function.
elemental function ichar_string(string) result(ich)
type(string_type), intent(in) :: string
integer :: ich
if (allocated(string%raw) .and. len(string) > 0) then
ich = ichar(string%raw(1:1))
else
ich = 0
end if
end function ichar_string
!> Code in ASCII collating sequence.
elemental function iachar_string(string) result(ich)
type(string_type), intent(in) :: string
integer :: ich
if (allocated(string%raw) .and. len(string) > 0) then
ich = iachar(string%raw(1:1))
else
ich = 0
end if
end function iachar_string
!> Return the character sequence represented by the string.
pure function char_string(string) result(character_string)
type(string_type), intent(in) :: string
character(len=len(string)) :: character_string
character_string = maybe(string)
end function char_string
!> Return the character sequence represented by the string.
elemental function char_string_pos(string, pos) result(character_string)
type(string_type), intent(in) :: string
integer, intent(in) :: pos
character(len=1) :: character_string
character_string = merge(string%raw(pos:pos), ' ', allocated(string%raw))
end function char_string_pos
!> Return the character sequence represented by the string.
pure function char_string_range(string, start, last) result(character_string)
type(string_type), intent(in) :: string
integer, intent(in) :: start
integer, intent(in) :: last
character(len=last-start+1) :: character_string
character_string = merge(string%raw(int(start, long):int(last, long)), &
repeat(' ', int(len(character_string), long)), allocated(string%raw))
end function char_string_range
!> Returns the character sequence hold by the string without trailing spaces.
elemental function trim_string(string) result(trimmed_string)
type(string_type), intent(in) :: string
type(string_type) :: trimmed_string
trimmed_string = trim(maybe(string))
end function trim_string
!> Left-adjust the character sequence represented by the string.
!> The length of the character sequence remains unchanged.
elemental function adjustl_string(string) result(adjusted_string)
type(string_type), intent(in) :: string
type(string_type) :: adjusted_string
adjusted_string = adjustl(maybe(string))
end function adjustl_string
!> Right-adjust the character sequence represented by the string.
!> The length of the character sequence remains unchanged.
elemental function adjustr_string(string) result(adjusted_string)
type(string_type), intent(in) :: string
type(string_type) :: adjusted_string
adjusted_string = adjustr(maybe(string))
end function adjustr_string
!> Repeats the character sequence hold by the string by the number of
!> specified copies.
elemental function repeat_string(string, ncopies) result(repeated_string)
type(string_type), intent(in) :: string
integer, intent(in) :: ncopies
type(string_type) :: repeated_string
repeated_string = repeat(maybe(string), ncopies)
end function repeat_string
!> Convert the character sequence hold by the input string to lower case
elemental function to_lower_string(string) result(lowercase_string)
type(string_type), intent(in) :: string
type(string_type) :: lowercase_string
lowercase_string%raw = to_lower_(maybe(string))
end function to_lower_string
!> Convert the character sequence hold by the input string to upper case
elemental function to_upper_string(string) result(uppercase_string)
type(string_type), intent(in) :: string
type(string_type) :: uppercase_string
uppercase_string%raw = to_upper_(maybe(string))
end function to_upper_string
!> Convert the character sequence hold by the input string to title case
elemental function to_title_string(string) result(titlecase_string)
type(string_type), intent(in) :: string
type(string_type) :: titlecase_string
titlecase_string%raw = to_title_(maybe(string))
end function to_title_string
!> Convert the character sequence hold by the input string to sentence case
elemental function to_sentence_string(string) result(sentence_string)
type(string_type), intent(in) :: string
type(string_type) :: sentence_string
sentence_string%raw = to_sentence_(maybe(string))
end function to_sentence_string
!> Reverse the character sequence hold by the input string
elemental function reverse_string(string) result(reversed_string)
type(string_type), intent(in) :: string
type(string_type) :: reversed_string
reversed_string%raw = reverse_(maybe(string))
end function reverse_string
!> Position of a sequence of character within a character sequence.
!> In this version both character sequences are represented by a string.
elemental function index_string_string(string, substring, back) result(pos)
type(string_type), intent(in) :: string
type(string_type), intent(in) :: substring
logical, intent(in), optional :: back
integer :: pos
pos = index(maybe(string), maybe(substring), optval(back, .false.))
end function index_string_string
!> Position of a sequence of character within a character sequence.
!> In this version the main character sequence is represented by a string.
elemental function index_string_char(string, substring, back) result(pos)
type(string_type), intent(in) :: string
character(len=*), intent(in) :: substring
logical, intent(in), optional :: back
integer :: pos
pos = index(maybe(string), substring, optval(back, .false.))
end function index_string_char
!> Position of a sequence of character within a character sequence.
!> In this version the sub character sequence is represented by a string.
elemental function index_char_string(string, substring, back) result(pos)
character(len=*), intent(in) :: string
type(string_type), intent(in) :: substring
logical, intent(in), optional :: back
integer :: pos
pos = index(string, maybe(substring), optval(back, .false.))
end function index_char_string
!> Scan a character sequence for any of the characters in a set of characters.
!> In this version both the character sequence and the character set are
!> represented by a string.
elemental function scan_string_string(string, set, back) result(pos)
type(string_type), intent(in) :: string
type(string_type), intent(in) :: set
logical, intent(in), optional :: back
integer :: pos
pos = scan(maybe(string), maybe(set), optval(back, .false.))
end function scan_string_string
!> Scan a character sequence for any of the characters in a set of characters.
!> In this version the character sequences is represented by a string.
elemental function scan_string_char(string, set, back) result(pos)
type(string_type), intent(in) :: string
character(len=*), intent(in) :: set
logical, intent(in), optional :: back
integer :: pos
pos = scan(maybe(string), set, optval(back, .false.))
end function scan_string_char
!> Scan a character sequence for any of the characters in a set of characters.
!> In this version the set of characters is represented by a string.
elemental function scan_char_string(string, set, back) result(pos)
character(len=*), intent(in) :: string
type(string_type), intent(in) :: set
logical, intent(in), optional :: back
integer :: pos
pos = scan(string, maybe(set), optval(back, .false.))
end function scan_char_string
!> Verify a character sequence for the absence any of the characters in
!> a set of characters. In this version both the character sequence and
!> the character set are represented by a string.
elemental function verify_string_string(string, set, back) result(pos)
type(string_type), intent(in) :: string
type(string_type), intent(in) :: set
logical, intent(in), optional :: back
integer :: pos
pos = verify(maybe(string), maybe(set), optval(back, .false.))
end function verify_string_string
!> Verify a character sequence for the absence any of the characters in
!> a set of characters. In this version the character sequences is
!> represented by a string.
elemental function verify_string_char(string, set, back) result(pos)
type(string_type), intent(in) :: string
character(len=*), intent(in) :: set
logical, intent(in), optional :: back
integer :: pos
pos = verify(maybe(string), set, optval(back, .false.))
end function verify_string_char
!> Verify a character sequence for the absence any of the characters in
!> a set of characters. In this version the set of characters is
!> represented by a string.
elemental function verify_char_string(string, set, back) result(pos)
character(len=*), intent(in) :: string
type(string_type), intent(in) :: set
logical, intent(in), optional :: back
integer :: pos
pos = verify(string, maybe(set), optval(back, .false.))
end function verify_char_string
!> Moves the allocated character scalar from 'from' to 'to'
!> No output
elemental subroutine move_string_string(from, to)
type(string_type), intent(inout) :: from
type(string_type), intent(inout) :: to
character(:), allocatable :: tmp
call move_alloc(from%raw, tmp)
call move_alloc(tmp, to%raw)
end subroutine move_string_string
!> Moves the allocated character scalar from 'from' to 'to'
!> No output
pure subroutine move_string_char(from, to)
type(string_type), intent(inout) :: from
character(len=:), intent(out), allocatable :: to
call move_alloc(from%raw, to)
end subroutine move_string_char
!> Moves the allocated character scalar from 'from' to 'to'
!> No output
pure subroutine move_char_string(from, to)
character(len=:), intent(inout), allocatable :: from
type(string_type), intent(out) :: to
call move_alloc(from, to%raw)
end subroutine move_char_string
!> Moves the allocated character scalar from 'from' to 'to'
!> No output
pure subroutine move_char_char(from, to)
character(len=:), intent(inout), allocatable :: from
character(len=:), intent(out), allocatable :: to
call move_alloc(from, to)
end subroutine move_char_char
!> Compare two character sequences for being greater.
!> In this version both character sequences are by a string.
elemental function gt_string_string(lhs, rhs) result(is_gt)
type(string_type), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_gt
is_gt = maybe(lhs) > maybe(rhs)
end function gt_string_string
!> Compare two character sequences for being greater.
!> In this version the left-hand side character sequences is by a string.
elemental function gt_string_char(lhs, rhs) result(is_gt)
type(string_type), intent(in) :: lhs
character(len=*), intent(in) :: rhs
logical :: is_gt
is_gt = maybe(lhs) > rhs
end function gt_string_char
!> Compare two character sequences for being greater.
!> In this version the right-hand side character sequences is by a string.
elemental function gt_char_string(lhs, rhs) result(is_gt)
character(len=*), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_gt
is_gt = lhs > maybe(rhs)
end function gt_char_string
!> Compare two character sequences for being less.
!> In this version both character sequences are by a string.
elemental function lt_string_string(lhs, rhs) result(is_lt)
type(string_type), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_lt
is_lt = rhs > lhs
end function lt_string_string
!> Compare two character sequences for being less.
!> In this version the left-hand side character sequences is by a string.
elemental function lt_string_char(lhs, rhs) result(is_lt)
type(string_type), intent(in) :: lhs
character(len=*), intent(in) :: rhs
logical :: is_lt
is_lt = rhs > lhs
end function lt_string_char
!> Compare two character sequences for being less.
!> In this version the right-hand side character sequences is by a string.
elemental function lt_char_string(lhs, rhs) result(is_lt)
character(len=*), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_lt
is_lt = rhs > lhs
end function lt_char_string
!> Compare two character sequences for being greater or equal.
!> In this version both character sequences are by a string.
elemental function ge_string_string(lhs, rhs) result(is_ge)
type(string_type), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_ge
is_ge = .not. (rhs > lhs)
end function ge_string_string
!> Compare two character sequences for being greater or equal.
!> In this version the left-hand side character sequences is by a string.
elemental function ge_string_char(lhs, rhs) result(is_ge)
type(string_type), intent(in) :: lhs
character(len=*), intent(in) :: rhs
logical :: is_ge
is_ge = .not. (rhs > lhs)
end function ge_string_char
!> Compare two character sequences for being greater or equal
!> In this version the right-hand side character sequences is by a string.
elemental function ge_char_string(lhs, rhs) result(is_ge)
character(len=*), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_ge
is_ge = .not. (rhs > lhs)
end function ge_char_string
!> Compare two character sequences for being less or equal.
!> In this version both character sequences are by a string.
elemental function le_string_string(lhs, rhs) result(is_le)
type(string_type), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_le
is_le = .not. (lhs > rhs)
end function le_string_string
!> Compare two character sequences for being less or equal.
!> In this version the left-hand side character sequences is by a string.
elemental function le_string_char(lhs, rhs) result(is_le)
type(string_type), intent(in) :: lhs
character(len=*), intent(in) :: rhs
logical :: is_le
is_le = .not. (lhs > rhs)
end function le_string_char
!> Compare two character sequences for being less or equal
!> In this version the right-hand side character sequences is by a string.
elemental function le_char_string(lhs, rhs) result(is_le)
character(len=*), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_le
is_le = .not. (lhs > rhs)
end function le_char_string
!> Compare two character sequences for equality.
!> In this version both character sequences are by a string.
elemental function eq_string_string(lhs, rhs) result(is_eq)
type(string_type), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_eq
is_eq = .not.(lhs > rhs)
if (is_eq) then
is_eq = .not.(rhs > lhs)
end if
end function eq_string_string
!> Compare two character sequences for equality.
!> In this version the left-hand side character sequences is by a string.
elemental function eq_string_char(lhs, rhs) result(is_eq)
type(string_type), intent(in) :: lhs
character(len=*), intent(in) :: rhs
logical :: is_eq
is_eq = .not.(lhs > rhs)
if (is_eq) then
is_eq = .not.(rhs > lhs)
end if
end function eq_string_char
!> Compare two character sequences for equality.
!> In this version the right-hand side character sequences is by a string.
elemental function eq_char_string(lhs, rhs) result(is_eq)
character(len=*), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_eq
is_eq = .not.(lhs > rhs)
if (is_eq) then
is_eq = .not.(rhs > lhs)
end if
end function eq_char_string
!> Compare two character sequences for inequality.
!> In this version both character sequences are by a string.
elemental function ne_string_string(lhs, rhs) result(is_ne)
type(string_type), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_ne
is_ne = lhs > rhs
if (.not.is_ne) then
is_ne = rhs > lhs
end if
end function ne_string_string
!> Compare two character sequences for inequality.
!> In this version the left-hand side character sequences is by a string.
elemental function ne_string_char(lhs, rhs) result(is_ne)
type(string_type), intent(in) :: lhs
character(len=*), intent(in) :: rhs
logical :: is_ne
is_ne = lhs > rhs
if (.not.is_ne) then
is_ne = rhs > lhs
end if
end function ne_string_char
!> Compare two character sequences for inequality.
!> In this version the right-hand side character sequences is by a string.
elemental function ne_char_string(lhs, rhs) result(is_ne)
character(len=*), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_ne
is_ne = lhs > rhs
if (.not.is_ne) then
is_ne = rhs > lhs
end if
end function ne_char_string
!> Lexically compare two character sequences for being greater.
!> In this version both character sequences are by a string.
elemental function lgt_string_string(lhs, rhs) result(is_lgt)
type(string_type), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_lgt
is_lgt = lgt(maybe(lhs), maybe(rhs))
end function lgt_string_string
!> Lexically compare two character sequences for being greater.
!> In this version the left-hand side character sequences is by a string.
elemental function lgt_string_char(lhs, rhs) result(is_lgt)
type(string_type), intent(in) :: lhs
character(len=*), intent(in) :: rhs
logical :: is_lgt
is_lgt = lgt(maybe(lhs), rhs)
end function lgt_string_char
!> Lexically compare two character sequences for being greater.
!> In this version the right-hand side character sequences is by a string.
elemental function lgt_char_string(lhs, rhs) result(is_lgt)
character(len=*), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_lgt
is_lgt = lgt(lhs, maybe(rhs))
end function lgt_char_string
!> Lexically compare two character sequences for being less.
!> In this version both character sequences are by a string.
elemental function llt_string_string(lhs, rhs) result(is_llt)
type(string_type), intent(in) :: lhs
type(string_type), intent(in) :: rhs
logical :: is_llt
is_llt = llt(maybe(lhs), maybe(rhs))
end function llt_string_string
!> Lexically compare two character sequences for being less.
!> In this version the left-hand side character sequences is by a string.
elemental function llt_string_char(lhs, rhs) result(is_llt)
type(string_type), intent(in) :: lhs
character(len=*), intent(in) :: rhs
logical :: is_llt
is_llt = llt(maybe(lhs), rhs)
end function llt_string_char
!> Lexically compare two character sequences for being less.