gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
Public Member Functions | List of all members
dc_string::split Interface Reference

Public Member Functions

subroutine split_cc (str, carray, sep, limit)
 

Detailed Description

Definition at line 170 of file dc_string.f90.

Member Function/Subroutine Documentation

◆ split_cc()

subroutine dc_string::split::split_cc ( character(*), intent(in)  str,
character(*), dimension(:), pointer  carray,
character(*), intent(in)  sep,
integer, intent(in), optional  limit 
)

Split string by separator

Splits string str by separator sep and returns in pointer array carray. carray must be null when passed. Error is returned if already allocated. If limit is a positive number, splits into at most limit fields. If limit is negative or 0, same as omitting it. Trailing spaces of str are removed. If sep is empty string, splits by whitespace.

Parameters
[in]strString to split
[out]carrayResult pointer array
[in]sepSeparator string
[in]limitMaximum number of fields (optional)

Definition at line 1509 of file dc_string.f90.

1510 use dc_types, only: string
1511 implicit none
1512 character(*), intent(in):: str
1513 character(*), pointer:: carray(:) !(out)
1514 character(*), intent(in):: sep
1515 integer, intent(in), optional:: limit
1516 integer :: num, cur, i, limitnum
1517 character(STRING) :: substr
1518 logical :: end_flag
1519 continue
1520 if (present(limit)) then
1521 if (limit > 0) then
1522 limitnum = limit
1523 else
1524 limitnum = 0
1525 end if
1526 else
1527 limitnum = 0
1528 end if
1529 if (len(trim(sep)) == 0) then
1530 num = 1
1531 substr = str
1532 ! 重複して無駄だが carray を allocate するため, 何分割するか
1533 ! 調べ, num に格納する.
1534 do
1535 cur = index(trim(substr), ' ')
1536 if (cur == 0) exit
1537 num = num + 1
1538 substr = adjustl(substr(cur + len(sep) :len(substr)))
1539 end do
1540 if (limitnum /= 0 .and. num > limitnum) num = limitnum
1541 allocate(carray(num))
1542 substr = str
1543 end_flag = .false.
1544 do i = 1, num
1545 cur = index(trim(substr), ' ')
1546 if (cur == 0 .or. i == num) end_flag = .true.
1547 if (end_flag) then
1548 carray(i) = substr
1549 exit
1550 else
1551 carray(i) = substr(1:cur - 1)
1552 end if
1553 substr = adjustl(substr(cur + len(sep) :len(substr)))
1554 end do
1555 else
1556 num = 1
1557 substr = str
1558 ! 重複して無駄だが carray を allocate するため, 何分割するか
1559 ! 調べ, num に格納する.
1560 do
1561 cur = index(substr, trim(sep))
1562 if (cur == 0) exit
1563 num = num + 1
1564 substr = substr(cur + len(sep) :len(substr))
1565 end do
1566 if (limitnum /= 0 .and. num > limitnum) num = limitnum
1567 allocate(carray(num))
1568 substr = str
1569 end_flag = .false.
1570 do i = 1, num
1571 cur = index(substr, trim(sep))
1572 if (cur == 0 .or. i == num) end_flag = .true.
1573 if (end_flag) then
1574 carray(i) = substr
1575 exit
1576 else
1577 carray(i) = substr(1:cur - 1)
1578 end if
1579 substr = substr(cur + len(sep) :len(substr))
1580 end do
1581 end if
1582 return
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public string
Character length for string
Definition dc_types.f90:137

References dc_types::string.


The documentation for this interface was generated from the following file: