dc_string::replace Interface Reference

Private Member Functions

recursive character(strlen) function replace (string, from, to, recursive, start_pos)
 

Detailed Description

Definition at line 128 of file dc_string.f90.

Constructor & Destructor Documentation

◆ replace()

recursive character(strlen) function dc_string::replace::replace ( character(*), intent(in)  string,
character(*), intent(in)  from,
character(*), intent(in)  to,
logical, intent(in), optional  recursive,
integer, intent(in), optional  start_pos 
)
private

Definition at line 1264 of file dc_string.f90.

1264  !
1265  ! 文字列 *string* に文字列 *from* が含まれる場合, その部分を文字列 *to*
1266  ! に置換して返します. 文字列 *from* が含まれない場合は *string*
1267  ! をそのまま返します. *from* が複数含まれる場合, 先頭の *from*
1268  ! のみが置換されます.
1269  !
1270  ! 全ての *from* を *to* へ変換したい場合には,
1271  ! オプショナル引数 *recursive* に .true. を与えてください.
1272  !
1273  ! デフォルトでは, 文字列の最初から検索を行います.
1274  ! オプショナル引数 *start_pos* を与える場合,
1275  ! *start_pos* 文字目から検索を行います.
1276  !
1277  ! If a string *from* is included in *string*, the string is
1278  ! replace to *to*, and the replaced string is returned.
1279  ! If a string *from* is not included, *string* is returned
1280  ! without change.
1281  ! When multiple *from* are included, only first *from* is replaced.
1282  !
1283  ! In order to replace all *from* to *to*, give ".true." to
1284  ! optional argument *recursive*.
1285  !
1286  ! By default, the string is searched from the top.
1287  ! If optional argument *start_pos* is given,
1288  ! the search is started from *start_pos*.
1289  !
1290  use dc_types, only: strlen => string
1291  implicit none
1292  character(STRLEN):: result
1293  character(*), intent(in):: string, from, to
1294  logical, intent(in), optional:: recursive
1295  integer, intent(in), optional:: start_pos
1296  integer:: sp
1297  integer:: i, isa, isb, iea, ieb
1298  integer:: ir
1299  continue
1300  if ( present(start_pos) ) then
1301  sp = start_pos
1302  else
1303  sp = 1
1304  end if
1305  if ( sp < 1 ) then
1306  sp = 1
1307  end if
1308 
1309  result = string
1310  i = index(result(sp:), from)
1311  if (i == 0) return
1312  i = i + sp - 1
1313  isa = i + len(from)
1314  isb = i + len(to)
1315  if (len(to) < len(from)) then
1316  iea = len(result)
1317  ieb = len(result) + len(to) - len(from)
1318  else
1319  iea = len(result) + len(from) - len(to)
1320  ieb = len(result)
1321  endif
1322  if (len(to) /= len(from)) result(isb:ieb) = result(isa:iea)
1323  result(i:i+len(to)-1) = to
1324 
1325  !-----------------------------------
1326  ! 再帰的処理
1327  ! Recursive process
1328  ir = index(result(i+len(to):), from)
1329  if ( len_trim(from) == 0 ) then
1330  ir = index(trim(result(i+len(to):)), from)
1331  end if
1332  if (ir /= 0) then
1333  if ( present(recursive) ) then
1334  if ( recursive ) then
1335  result = replace( string = result, &
1336  & from = from, to = to, &
1337  & recursive = recursive, &
1338  & start_pos = i+len(to) )
1339  end if
1340  end if
1341  end if
1342 
種別型パラメタを提供します。
Definition: dc_types.f90:49
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118

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