Re: Parsing challenge to reduce blanks
- From: "James Van Buskirk" <not_valid@xxxxxxxxxxx>
- Date: Tue, 2 Aug 2005 12:28:16 -0600
"David Frank" <dave_frank@xxxxxxxxxxx> wrote in message
news:h8OHe.1956$ns.1232@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> "James Van Buskirk" <not_valid@xxxxxxxxxxx> wrote in message
> news:LtSdnYxDq_5JO3LfRVn-ow@xxxxxxxxxxxxxx
> > "David Frank" <dave_frank@xxxxxxxxxxx> wrote in message
> > news:neFHe.12621$oZ.9766@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> >> function reduce_blanks(line) result (outline)
> >> character(*) :: line
> >> character(len(line)) :: outline
> >> character :: a(len(line))
> >> a = transfer(line,a)
> >> forall (i=1:size(a)-1, a(i)==' '.and.a(i+1)==' ') a(i) = char(0)
> >> outline = transfer(pack(a,a /= char(0), spread(' ',1,size(a))),
outline)
> >> end function reduce_blanks
> > Your solution is fairly close to mine,
> If you say so, altho I didnt see my technique of 1st marking the repeats
> with a forall and then
> discarding them with a pack that has a spread to fill in the trailing
blanks
> in your code.
Well, yes, I didn't make that particular mistake. If the input
string already contained your sentinel character, the output
would not, so it would be incorrect.
> Didnt you say your solution has a problem with exact size text in line?
As does yours.
> > spread out over more statements. It suffers the same problem, though.
> > Compressing
> > repeated spaces into one requires that
> > len(reduce_blanks('xxx'//repeat(' ',n))) = merge(4,3,n > 0)
> Dont be so obtuse, show me a sample line that wont get properly reduced
> because
> my solution "suffers the same problem" as yours.
Your canonical sample suffers this problem.
> > Obviously this can be achieved without introducing further
> > executable statements.
> Well first show me my problem and I will try to fix it..
I'll try:
program test
implicit none
integer i
do i = 0,2
write(*,*) 'i = ', i
call showme('xxx'//repeat(' ',i))
end do
contains
function reduce_blanks(line) result (outline)
character(*) :: line
character(len(line)) :: outline
character :: a(len(line))
a = transfer(line,a)
forall (i=1:size(a)-1, a(i)==' '.and. &
a(i+1)==' ') a(i) = char(0)
outline = transfer(pack(a,a /= char(0), &
spread(' ',1,size(a))), outline)
end function reduce_blanks
subroutine showme(x)
character(*), intent(in) :: x
write(*,*) 'len = ', len(x)
write(*,*) 'x = ', x
end subroutine showme
end program test
The output I get with lf95 -f95 -nconcc is:
i = 0
len = 3
x = xxx
i = 1
len = 4
x = xxx
i = 2
len = 5
x = xxx
However, when i = 2, len(x) should be 4 because the two blanks
at the end should get compressed into one. Similar problems
occur with your test string, but your testing methodology
doesn't permit you to see the effect of the several trailing
blanks it has.
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
.
- Follow-Ups:
- Re: Parsing challenge to reduce blanks
- From: David Frank
- Re: Parsing challenge to reduce blanks
- References:
- Parsing challenge to reduce blanks
- From: David Frank
- Re: Parsing challenge to reduce blanks
- From: David Frank
- Re: Parsing challenge to reduce blanks
- From: James Van Buskirk
- Re: Parsing challenge to reduce blanks
- From: David Frank
- Parsing challenge to reduce blanks
- Prev by Date: Re: Parsing challenge to reduce blanks
- Next by Date: Re: Parsing challenge to reduce blanks
- Previous by thread: Re: Parsing challenge to reduce blanks
- Next by thread: Re: Parsing challenge to reduce blanks
- Index(es):
Relevant Pages
|