-
Notifications
You must be signed in to change notification settings - Fork 191
Revival string list #470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
milancurcic
merged 41 commits into
fortran-lang:master
from
aman-godara:revival_string_list
Aug 26, 2021
Merged
Revival string list #470
Changes from 34 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
405e06f
Add module for list of strings
arjenmarkus 320caed
Correct typo
arjenmarkus c75dd20
fixed a bug in append_stringlist
aman-godara ecaa0bf
used concept of forward backward indexes, refactored code to use stdl…
aman-godara e7604bd
resolved stash conflicts
aman-godara bc9eda7
resolved 2 bugs, improved aesthetics of code
aman-godara 5f72c18
added stringlist.f90 to cmakelists & makefile.manual
aman-godara 9bbcdf7
blocked integer indexes, added copy function, added comments, stopped…
aman-godara 0128f4e
cleaned PR and saved comments in another branch
aman-godara 4bf2738
removed top comments
aman-godara 5f8c484
resolved a bug in get, improved the implementation of the design
aman-godara 7af5987
resolved a bug in destroy, added test cases
aman-godara e0e0a96
this might resolve the error
aman-godara 3534150
added equality and inequality operators, added support for chararray …
aman-godara b577a54
added first test case
aman-godara 9bfab34
Fix manual makefile build
awvwgk 42487ea
added 2nd test case for insert_at
aman-godara 3ddfa93
added 3rd test case for insert_at
aman-godara 872b2cd
added test case for append prepend
aman-godara dd6aea1
cleared the previous documentation for string_list
aman-godara 2918270
'100' is not equal to '100 ' in other compilers
aman-godara 961a2e7
Makefile.manual takes backslash instead of slash
aman-godara 9c758c0
added insert_at test cases for array and stringlist
aman-godara 4db28c8
first draft of documentation: isnert_at, get, len, derived types
aman-godara afb318e
added constructor for carray & sarray, changed intent of clear_list s…
aman-godara a0c20cc
replaced copy function with appropriate comments
aman-godara 35b28f5
solved bug: inserting a list in itself
aman-godara 8ed81c0
added test cases for constructor stringlist_type()
aman-godara bca711f
added documentation for clear, constructor and fidx/bidx
aman-godara 38052c2
corrected some bugs in documentation, added stringlist to index.md
aman-godara 1584eeb
removed capacity function
aman-godara fb3ddd5
removed size component, changed the logic of len function, modified c…
aman-godara 3777c04
renamed stringlist to stringlist_type
aman-godara 948d064
made to_current_idxn as private
aman-godara f0a668c
Apply suggestions from code review
aman-godara 4b69e3d
added constructor for string array and its test cases
aman-godara 2c3bcdb
corrected some mistakes in the documentation
aman-godara 9a0a33a
added documentation for operators //, == and /=
aman-godara 2e5e822
some minor improvements in doc
aman-godara cea79e8
dependency to_string has been moved to stdlib_strings
aman-godara 39297bd
Merge branch 'master' into revival_string_list
aman-godara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,379 @@ | ||
--- | ||
title: stringlist type | ||
--- | ||
|
||
# `stdlib_stringlist_type` module (1-D List of Strings) | ||
|
||
[TOC] | ||
|
||
## Introduction | ||
|
||
The `stdlib_stringlist_type` module provides with 2 derived types to deal with list of strings. | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`stringlist_type` derived type represents a one-dimensional list of variable-length strings which is compatible with Fortran intrinsic character and `stringlist_type` derived type represents an index to access, modify the elements of a stringlist and insert strings to a stringlist. | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Derived type provided | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### `stringlist_type` derived type | ||
|
||
The `stringlist_type` derived type represents one-dimensional list of strings. | ||
The internal representation of the list is implementation dependent and is not visible to the user of the module. | ||
|
||
#### Status | ||
|
||
Experimental | ||
|
||
|
||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### `stringlist_index_type` derived type | ||
|
||
An instance of the derived type `stringlist_index_type` represents either a forward index OR a backward index. | ||
The internal representation is implementation dependent and is not visible to the user of the module. | ||
`list_head` and `list_tail` are 2 special instances of this type representing the head and the tail of a stringlist respectively. | ||
An instance is independent of the stringlist it is used with and hence, an index can be used with multiple stringlists in the same program. | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Status | ||
|
||
Experimental | ||
|
||
|
||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### fidx/bidx | ||
|
||
#### Description | ||
|
||
`fidx`: Returns an instance which represents forward index `idx`. | ||
`bidx`: Returns an instance which represents backward index `idx`. | ||
|
||
#### Syntax | ||
|
||
For fidx: `res = [[stdlib_stringlist_type(module):fidx()]] (idx)`. | ||
For bidx: `res = [[stdlib_stringlist_type(module):bidx()]] (idx)`. | ||
|
||
#### Status | ||
|
||
Experimental. | ||
|
||
#### Class | ||
|
||
Pure function. | ||
|
||
#### Argument | ||
|
||
- `idx`: integer. | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This argument is intent(in). | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Result value | ||
|
||
The result is of type `stringlist_index_type`. | ||
|
||
#### Example | ||
|
||
```fortran | ||
program demo_fidx_bidx | ||
use stdlib_stringlist_type, only: stringlist_type, stringlist_index_type, fidx, bidx | ||
implicit none | ||
|
||
type(stringlist_type) :: stringlist | ||
type(stringlist_index_type) :: index | ||
|
||
index = fidx(1) | ||
|
||
!> inserting 2 elements to the stringlist | ||
call stringlist%insert_at( fidx(1), "Element No. one" ) | ||
call stringlist%insert_at( index, "Element No. two" ) | ||
! stringlist <-- {"Element No. two", "Element No. one"} | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
index = bidx(3) | ||
|
||
!> inserting 2 elements to the stringlist | ||
call stringlist%insert_at( bidx(1), "Element No. three" ) | ||
call stringlist%insert_at( index, "Element No. four" ) | ||
! stringlist <-- {"Element No. two", "Element No. four", | ||
"Element No. one", "Element No. three"} | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
end program demo_fidx_bidx | ||
``` | ||
|
||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### Constructor for stringlist | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Description | ||
|
||
No arguments given: Initializes an empty stringlist(a list containing no elements in it). | ||
|
||
With argument: Initializes a stringlist equivalent to the input array `array` i.e. a stringlist containing all elements of the input array `array` in the same order. | ||
|
||
#### Syntax | ||
|
||
- No arguments given: `res = [[stdlib_stringlist_type(module):stringlist_type(interface)]] ()` | ||
|
||
- With argument: `res = [[stdlib_stringlist_type(module):stringlist_type(interface)]] (array)` | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Status | ||
|
||
Experimental | ||
|
||
#### Class | ||
|
||
Pure function. | ||
|
||
#### Argument | ||
|
||
1). No arguments. | ||
|
||
2). With argument: | ||
- `array`: array of Character scalar or array of [[stdlib_string_type(module):string_type(type)]]. | ||
This argument is intent(in). | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Result value | ||
|
||
The result is an instance of type `stringlist_type`. | ||
|
||
#### Example | ||
|
||
```fortran | ||
program demo_constructor | ||
use stdlib_stringlist_type, only: stringlist_type | ||
use stdlib_string_type, only: string_type | ||
implicit none | ||
|
||
type(stringlist_type) :: stringlist | ||
|
||
stringlist = stringlist_type() | ||
! stringlist <-- { } (empty stringlist) | ||
|
||
stringlist = stringlist_type(["#1", "#2", "#3"]) | ||
! stringlist <-- {"#1", "#2", "#3"} | ||
|
||
stringlist = stringlist_type([string_type("#1"), string_type("#2")]) | ||
! stringlist <-- {"#1", "#2"} | ||
|
||
end program demo_constructor | ||
``` | ||
|
||
|
||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### insert_at | ||
|
||
#### Description | ||
|
||
Inserts the string `string` _AT_ the index `idx`, so that the newly added element is present at index `idx` after insertion. Inserting an element _AT_ index beyond `length + 1` inserts the element _AT_ `list_tail`, and likewise inserting _AT_ a non-positive index inserts the element _AT_ `list_head`. | ||
|
||
#### Syntax | ||
|
||
`call [[stdlib_stringlist_type(module):stringlist_type(type)]]%[[stdlib_stringlist_type(module):insert_at(generic)]] (idx, string)` | ||
|
||
#### Status | ||
|
||
Experimental. | ||
|
||
#### Class | ||
|
||
Pure subroutine. | ||
|
||
#### Argument | ||
|
||
- `idx`: [[stdlib_stringlist_type(module):stringlist_index_type(type)]]. | ||
This argument is intent(in). | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- `string`: Character scalar or [[stdlib_string_type(module):string_type(type)]]. | ||
This argument is intent(in). | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Result value | ||
|
||
No result. | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Example | ||
|
||
```fortran | ||
program demo_insert_at | ||
use stdlib_stringlist_type, only: stringlist_type, stringlist_index_type, fidx, bidx | ||
use stdlib_string_type, only: string_type | ||
implicit none | ||
|
||
type(stringlist_type) :: stringlist | ||
type(stringlist_index_type) :: index | ||
|
||
index = fidx(1) | ||
call stringlist%insert_at( index, "Element No. one" ) | ||
! stringlist <-- {"Element No. one"} | ||
|
||
index = bidx(1) | ||
call stringlist%insert_at( index, string_type( "Element No. two" ) ) | ||
! stringlist <-- {"Element No. one", "Element No. two"} | ||
|
||
call stringlist%insert_at( fidx(2), string_type( "Element No. three" ) ) | ||
! stringlist <-- {"Element No. one", "Element No. three", "Element No. two"} | ||
|
||
call stringlist%insert_at( bidx(1), "Element No. four" ) | ||
! stringlist <-- {"Element No. one", "Element No. three", "Element No. two", "Element No. four"} | ||
|
||
end program demo_insert_at | ||
``` | ||
|
||
|
||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### get | ||
|
||
#### Description | ||
|
||
Returns the string present currently at the index `idx` in a stringlist. If index `idx` is out of bounds, then an empty string is returned. | ||
|
||
#### Syntax | ||
|
||
`res = [[stdlib_stringlist_type(module):stringlist_type(type)]]%[[stdlib_stringlist_type(module):get(generic)]] (idx)` | ||
|
||
#### Status | ||
|
||
Experimental. | ||
|
||
#### Class | ||
|
||
Pure function. | ||
|
||
#### Argument | ||
|
||
- `idx`: [[stdlib_stringlist_type(module):stringlist_index_type(type)]]. | ||
This argument is intent(in). | ||
|
||
#### Result value | ||
|
||
The result is a string of type `string_type`. | ||
|
||
#### Example | ||
|
||
```fortran | ||
program demo_get | ||
use stdlib_stringlist_type, only: stringlist_type, fidx, bidx | ||
use stdlib_string_type, only: string_type | ||
implicit none | ||
|
||
type(stringlist_type) :: stringlist | ||
type(string_type) :: output | ||
|
||
!> inserting 4 elements to the stringlist | ||
call stringlist%insert_at( fidx(1), "Element No. one" ) | ||
call stringlist%insert_at( fidx(1), "Element No. two" ) | ||
call stringlist%insert_at( fidx(1), "Element No. three" ) | ||
call stringlist%insert_at( fidx(1), "Element No. four" ) | ||
! stringlist <-- {"Element No. four", "Element No. three", "Element No. two", "Element No. one"} | ||
|
||
output = stringlist%get( fidx(1) ) | ||
! output <-- "Element No. four" | ||
|
||
output = stringlist%get( bidx(1) ) | ||
! output <-- "Element No. one" | ||
|
||
!> accessing out of bounds index | ||
output = stringlist%get( bidx(5) ) | ||
! output <-- "" | ||
output = stringlist%get( fidx(0) ) | ||
! output <-- "" | ||
|
||
end program demo_get | ||
``` | ||
|
||
|
||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### len | ||
|
||
#### Description | ||
|
||
Returns the number of elements present currently in the stringlist. | ||
|
||
#### Syntax | ||
|
||
`res = [[stdlib_stringlist_type(module):stringlist_type(type)]]%[[stdlib_stringlist_type(module):len()]] ()` | ||
|
||
#### Status | ||
|
||
Experimental. | ||
|
||
#### Class | ||
|
||
Pure function. | ||
|
||
#### Argument | ||
|
||
No arguments. | ||
|
||
#### Result value | ||
|
||
The result is of type `integer`. | ||
|
||
#### Example | ||
|
||
```fortran | ||
program demo_len | ||
use stdlib_stringlist_type, only: stringlist_type, bidx | ||
implicit none | ||
|
||
type(stringlist_type) :: stringlist | ||
integer :: output | ||
|
||
output = stringlist%len() | ||
! output <-- 0 | ||
|
||
!> inserting 2 elements to the stringlist | ||
call stringlist%insert_at( bidx(1), "Element No. one" ) | ||
call stringlist%insert_at( bidx(1), "Element No. two" ) | ||
! stringlist <-- {"Element No. one", "Element No. two"} | ||
|
||
print'(a)', stringlist%len() | ||
! 2 | ||
|
||
end program demo_len | ||
``` | ||
|
||
|
||
<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --> | ||
### clear | ||
|
||
#### Description | ||
|
||
Removes all elements from a stringlist. | ||
|
||
#### Syntax | ||
|
||
`call [[stdlib_stringlist_type(module):stringlist_type(type)]]%[[stdlib_stringlist_type(module):clear()]] ()` | ||
|
||
#### Status | ||
|
||
Experimental. | ||
|
||
#### Class | ||
|
||
Pure subroutine. | ||
|
||
#### Argument | ||
|
||
No arguments. | ||
|
||
#### Result value | ||
|
||
No result. | ||
aman-godara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Example | ||
|
||
```fortran | ||
program demo_clear | ||
use stdlib_stringlist_type, only: stringlist_type, fidx | ||
implicit none | ||
|
||
type(stringlist_type) :: stringlist | ||
|
||
!> inserting 2 elements to the stringlist | ||
call stringlist%insert_at( fidx(1), "Element No. one" ) | ||
call stringlist%insert_at( fidx(1), "Element No. two" ) | ||
! stringlist <-- {"Element No. two", "Element No. one"} | ||
|
||
call stringlist%clear() | ||
! stringlist <-- { } (empty stringlist) | ||
|
||
!> inserting 1 element to the stringlist | ||
call stringlist%insert_at( fidx(1), "Element No. one" ) | ||
! stringlist <-- {"Element No. one"} | ||
|
||
end program demo_clear | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.