Skip to content

Commit e646fc5

Browse files
committed
Merge branch 'master' into zoziha/feature/format_string
2 parents b05cbae + c2b8338 commit e646fc5

File tree

4 files changed

+513
-60
lines changed

4 files changed

+513
-60
lines changed

doc/specs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This is and index/directory of the specifications (specs) for each new module/fe
1818
- [kinds](./stdlib_kinds.html) - Kind parameters
1919
- [linalg](./stdlib_linalg.html) - Linear Algebra
2020
- [logger](./stdlib_logger.html) - Runtime logging system
21+
- [math](./stdlib_math.html) - General purpose mathematical functions
2122
- [optval](./stdlib_optval.html) - Fallback value for optional arguments
2223
- [quadrature](./stdlib_quadrature.html) - Numerical integration
2324
- [sorting](./stdlib_sorting.html) - Sorting of rank one arrays

doc/specs/stdlib_strings.md

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ end program demo_slice
280280
Returns the starting index of the `occurrence`th occurrence of the substring `pattern`
281281
in the input string `string`.
282282
Default value of `occurrence` is set to `1`.
283-
If `consider_overlapping` is not provided or is set to `.true.` the function counts two overlapping occurrences of substring as two different occurrences.
283+
If `consider_overlapping` is not provided or is set to `.true.` the function counts two overlapping occurrences of substring `pattern` as two different occurrences.
284284
If `occurrence`th occurrence is not found, function returns `0`.
285285

286286
#### Syntax
@@ -308,7 +308,7 @@ Elemental function
308308

309309
#### Result value
310310

311-
The result is a scalar of integer type or integer array of rank equal to the highest rank among all dummy arguments.
311+
The result is a scalar of integer type or an integer array of rank equal to the highest rank among all dummy arguments.
312312

313313
#### Example
314314

@@ -317,7 +317,7 @@ program demo_find
317317
use stdlib_string_type, only: string_type, assignment(=)
318318
use stdlib_strings, only : find
319319
implicit none
320-
string_type :: string
320+
type(string_type) :: string
321321
322322
string = "needle in the character-stack"
323323
@@ -328,6 +328,113 @@ program demo_find
328328
end program demo_find
329329
```
330330

331+
332+
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
333+
### `replace_all`
334+
335+
#### Description
336+
337+
Replaces all occurrences of substring `pattern` in the input `string` with the replacement `replacement`.
338+
Occurrences overlapping on a base occurrence will not be replaced.
339+
340+
#### Syntax
341+
342+
`string = [[stdlib_strings(module):replace_all(interface)]] (string, pattern, replacement)`
343+
344+
#### Status
345+
346+
Experimental
347+
348+
#### Class
349+
350+
Pure function
351+
352+
#### Argument
353+
354+
- `string`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
355+
This argument is intent(in).
356+
- `pattern`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
357+
This argument is intent(in).
358+
- `replacement`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
359+
This argument is intent(in).
360+
361+
#### Result value
362+
363+
The result is of the same type as `string`.
364+
365+
#### Example
366+
367+
```fortran
368+
program demo_replace_all
369+
use stdlib_string_type, only: string_type, assignment(=)
370+
use stdlib_strings, only : replace_all
371+
implicit none
372+
type(string_type) :: string
373+
374+
string = "hurdles here, hurdles there, hurdles everywhere"
375+
! string <-- "hurdles here, hurdles there, hurdles everywhere"
376+
377+
print'(a)', replace_all(string, "hurdles", "learn from")
378+
! "learn from here, learn from there, learn from everywhere"
379+
380+
string = replace_all(string, "hurdles", "technology")
381+
! string <-- "technology here, technology there, technology everywhere"
382+
383+
end program demo_replace_all
384+
```
385+
386+
387+
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
388+
### `count`
389+
390+
#### Description
391+
392+
Returns the number of times the substring `pattern` has occurred in the input string `string`.
393+
If `consider_overlapping` is not provided or is set to `.true.` the function counts two overlapping occurrences of substring `pattern` as two different occurrences.
394+
395+
#### Syntax
396+
397+
`string = [[stdlib_strings(module):count(interface)]] (string, pattern [, consider_overlapping])`
398+
399+
#### Status
400+
401+
Experimental
402+
403+
#### Class
404+
405+
Elemental function
406+
407+
#### Argument
408+
409+
- `string`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
410+
This argument is intent(in).
411+
- `pattern`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
412+
This argument is intent(in).
413+
- `consider_overlapping`: logical.
414+
This argument is intent(in) and optional.
415+
416+
#### Result value
417+
418+
The result is a scalar of integer type or an integer array of rank equal to the highest rank among all dummy arguments.
419+
420+
#### Example
421+
422+
```fortran
423+
program demo_count
424+
use stdlib_string_type, only: string_type, assignment(=)
425+
use stdlib_strings, only : count
426+
implicit none
427+
type(string_type) :: string
428+
429+
string = "How much wood would a woodchuck chuck if a woodchuck could chuck wood?"
430+
431+
print *, count(string, "wood") ! 4
432+
print *, count(string, ["would", "chuck", "could"]) ! [1, 4, 1]
433+
print *, count("a long queueueueue", "ueu", [.false., .true.]) ! [2, 4]
434+
435+
end program demo_count
436+
```
437+
331438
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
332439
### `format_to_string`
333440

0 commit comments

Comments
 (0)