@@ -361,51 +361,51 @@ contains
361
361
362
362
end function reverse
363
363
364
- pure function slice(string, start, end , stride, include_end ) result(sliced_string)
364
+ pure function slice(string, start, last , stride, include_last ) result(sliced_string)
365
365
character(len=*), intent(in) :: string
366
- integer, intent(in), optional :: start, end , stride
367
- logical, intent(in), optional :: include_end
368
- integer :: start_index, end_index , stride_vector, n, i, j
366
+ integer, intent(in), optional :: first, last , stride
367
+ logical, intent(in), optional :: include_last
368
+ integer :: first_index, last_index , stride_vector, n, i, j
369
369
character(len=:), allocatable :: sliced_string
370
370
371
- start_index = 1
372
- end_index = len(string)
371
+ first_index = 1
372
+ last_index = len(string)
373
373
stride_vector = 1
374
374
if (len(string) > 0) then
375
375
if (present(stride)) then
376
376
if (stride /= 0) then
377
377
if (stride < 0) then
378
- start_index = len(string)
379
- end_index = 1
378
+ first_index = len(string)
379
+ last_index = 1
380
380
end if
381
381
stride_vector = stride
382
382
end if
383
383
else
384
- if (present(start ) .and. present(end )) then
385
- if (end < start ) then
384
+ if (present(first ) .and. present(last )) then
385
+ if (last < first ) then
386
386
stride_vector = -1
387
387
end if
388
388
end if
389
389
end if
390
390
391
- if (present(start )) then
392
- start_index = clip(start , 1, len(string))
391
+ if (present(first )) then
392
+ first_index = clip(first , 1, len(string))
393
393
end if
394
- if (present(end )) then
395
- end_index = clip(end , 1, len(string))
394
+ if (present(last )) then
395
+ last_index = clip(last , 1, len(string))
396
396
end if
397
397
398
- n = int((end_index - start_index ) / stride_vector)
398
+ n = int((last_index - first_index ) / stride_vector)
399
399
allocate(character(len=max(0, n + 1)) :: sliced_string)
400
400
401
- if (present(include_end )) then
402
- if (include_end ) then
403
- start_index = end_index - (n * stride_vector)
401
+ if (present(include_last )) then
402
+ if (include_last ) then
403
+ first_index = last_index - (n * stride_vector)
404
404
end if
405
405
end if
406
406
407
407
j = 1
408
- do i = start_index, end_index , stride_vector
408
+ do i = first_index, last_index , stride_vector
409
409
sliced_string(j:j) = string(i:i)
410
410
j = j + 1
411
411
end do
0 commit comments