Skip to content

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
merged 41 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
405e06f
Add module for list of strings
arjenmarkus Feb 3, 2021
320caed
Correct typo
arjenmarkus Feb 4, 2021
c75dd20
fixed a bug in append_stringlist
aman-godara Jul 24, 2021
ecaa0bf
used concept of forward backward indexes, refactored code to use stdl…
aman-godara Jul 24, 2021
e7604bd
resolved stash conflicts
aman-godara Jul 24, 2021
bc9eda7
resolved 2 bugs, improved aesthetics of code
aman-godara Jul 24, 2021
5f72c18
added stringlist.f90 to cmakelists & makefile.manual
aman-godara Jul 28, 2021
9bbcdf7
blocked integer indexes, added copy function, added comments, stopped…
aman-godara Jul 28, 2021
0128f4e
cleaned PR and saved comments in another branch
aman-godara Jul 28, 2021
4bf2738
removed top comments
aman-godara Jul 28, 2021
5f8c484
resolved a bug in get, improved the implementation of the design
aman-godara Jul 31, 2021
7af5987
resolved a bug in destroy, added test cases
aman-godara Jul 31, 2021
e0e0a96
this might resolve the error
aman-godara Jul 31, 2021
3534150
added equality and inequality operators, added support for chararray …
aman-godara Aug 1, 2021
b577a54
added first test case
aman-godara Aug 1, 2021
9bfab34
Fix manual makefile build
awvwgk Aug 2, 2021
42487ea
added 2nd test case for insert_at
aman-godara Aug 2, 2021
3ddfa93
added 3rd test case for insert_at
aman-godara Aug 2, 2021
872b2cd
added test case for append prepend
aman-godara Aug 3, 2021
dd6aea1
cleared the previous documentation for string_list
aman-godara Aug 3, 2021
2918270
'100' is not equal to '100 ' in other compilers
aman-godara Aug 3, 2021
961a2e7
Makefile.manual takes backslash instead of slash
aman-godara Aug 3, 2021
9c758c0
added insert_at test cases for array and stringlist
aman-godara Aug 5, 2021
4db28c8
first draft of documentation: isnert_at, get, len, derived types
aman-godara Aug 8, 2021
afb318e
added constructor for carray & sarray, changed intent of clear_list s…
aman-godara Aug 15, 2021
a0c20cc
replaced copy function with appropriate comments
aman-godara Aug 15, 2021
35b28f5
solved bug: inserting a list in itself
aman-godara Aug 15, 2021
8ed81c0
added test cases for constructor stringlist_type()
aman-godara Aug 16, 2021
bca711f
added documentation for clear, constructor and fidx/bidx
aman-godara Aug 16, 2021
38052c2
corrected some bugs in documentation, added stringlist to index.md
aman-godara Aug 16, 2021
1584eeb
removed capacity function
aman-godara Aug 17, 2021
fb3ddd5
removed size component, changed the logic of len function, modified c…
aman-godara Aug 18, 2021
3777c04
renamed stringlist to stringlist_type
aman-godara Aug 18, 2021
948d064
made to_current_idxn as private
aman-godara Aug 19, 2021
f0a668c
Apply suggestions from code review
aman-godara Aug 19, 2021
4b69e3d
added constructor for string array and its test cases
aman-godara Aug 20, 2021
2c3bcdb
corrected some mistakes in the documentation
aman-godara Aug 20, 2021
9a0a33a
added documentation for operators //, == and /=
aman-godara Aug 20, 2021
2e5e822
some minor improvements in doc
aman-godara Aug 20, 2021
cea79e8
dependency to_string has been moved to stdlib_strings
aman-godara Aug 24, 2021
39297bd
Merge branch 'master' into revival_string_list
aman-godara Aug 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 211 additions & 0 deletions doc/specs/stdlib_stringlist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
---
title: stringlist
---

# `stdlib_stringlist` module (1-D List of Strings)

[TOC]

## Introduction

The `stdlib_stringlist` module provides with 2 derived types to deal with list of strings.
`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.

## Derived type provided

<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
### `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.

#### Status

Experimental


<!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -->
### insert_at

#### Description

Inserts the string `string` at the index `idx` such that after insertion is done the newly added element is at index `idx`.

#### Syntax

`call [[stdlib_stringlist(module):stringlist_type(type)]]%[[stdlib_stringlist(module):insert_at(generic)]] (idx, string)`

#### Status

Experimental.

#### Class

Pure subroutine.

#### Argument

- `idx`: [[stdlib_stringlist(module):stringlist_index_type(type)]].
This argument is intent(in).

- `string`: Character scalar or [[stdlib_string_type(module):string_type(type)]].
This argument is intent(in).

#### Result value

No result.

#### Example

```fortran
program demo_insert_at
use stdlib_stringlist, only: stringlist_type, insert_at, 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 the given stringlist. If `idx` is out of bounds an empty string is returned.

#### Syntax

`res = [[stdlib_stringlist(module):stringlist_type(type)]]%[[stdlib_stringlist(module):get(generic)]] (idx)`

#### Status

Experimental.

#### Class

Pure function.

#### Argument

- `idx`: [[stdlib_stringlist(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, only: stringlist_type, insert_at, fidx, get
use stdlib_string_type, only: string_type
implicit none

type(stringlist_type) :: stringlist
type(string_type) :: output

!> adding 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 in the stringlist.

#### Syntax

`res = [[stdlib_stringlist(module):stringlist_type(type)]]%[[stdlib_stringlist(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, only: stringlist_type, insert_at, bidx, len
implicit none

type(stringlist_type) :: stringlist
integer :: output

output = stringlist%len()
! output <-- 0

!> adding 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"}

output = stringlist%len()
! output <-- 2

end program demo_len
```
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ set(SRC
stdlib_specialfunctions.f90
stdlib_specialfunctions_legendre.f90
stdlib_quadrature_gauss.f90
stdlib_stringlist.f90
${outFiles}
)

Expand Down
4 changes: 4 additions & 0 deletions src/Makefile.manual
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ SRC = f18estop.f90 \
stdlib_logger.f90 \
stdlib_quadrature_gauss.f90 \
stdlib_strings.f90 \
stdlib_stringlist.f90 \
$(SRCGEN)

LIB = libstdlib.a
Expand Down Expand Up @@ -155,3 +156,6 @@ stdlib_math_linspace.o: \
stdlib_math_logspace.o: \
stdlib_math_linspace.o
stdlib_linalg_outer_product.o: stdlib_linalg.o
stdlib_stringlist.o: stdlib_string_type.o \
stdlib_math.o \
stdlib_optval.o
Loading