Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #13466

Re: Memoline replaces tabs with spaces?

From "Wolfgang Riedmann" <wriedmann@gmail.com>
Newsgroups comp.lang.clipper.visual-objects
Subject Re: Memoline replaces tabs with spaces?
Date 2021-11-16 07:01 +0100
Message-ID <ivgvq7Fs6qtU1@mid.individual.net> (permalink)
References <5c709d09-dd09-47c0-85b1-1577e502de07n@googlegroups.com>

Show all headers | View raw


Hi Gregory,

the best would be to build your own parser.

Please se below. It may not the best or cleanest code, but it
definitely works for me.

Wolfgang


> I started to bulid a small XLS/ODS table parser using multiline edit
> field where I paste a copied cell range. CTRL-C/CTRL-V sets TAB
> chr(9) between each field what is ok.  However wher I read
> consecutive lines using:  cLine :=
> AllTrim(MemoLine(SELF:oDCmleInput:Value,50,nRow)) where nRow is
> increasing up to empty(cLine) then tab character(s) are replaced by
> space(s).  Is this a normal MemoLine behavour?  Is there a way to
> stop him doing that i.e. leave chr(9) in line or must I build my own
> char-by-char/line-by-line parser?  Kind regards Gregory

function PasteArrayFromClipboard() as array pascal 
	local oClipboard		as ClipBoard
	local aLines			as array
	local aReturn			as array
	local nLines			as dword
	local nLine				as dword
	local cString			as string
	local aDetail			as array
	
	oClipboard		:= ClipBoard{}
	cString		:= oClipBoard:RetrieveString()
	aLines		:= String2Lines( cString )
	nLines		:= ALen( aLines )
	aReturn		:= ArrayNew( nLines )
	for nLine := 1 upto nLines
		aDetail		:= String2Array( aLines[nLine], _chr( 9 ) )
		aReturn[nLine]	:= aDetail 
	next
	
	return aReturn

function String2Lines( cString as string ) as array
	local aResult		as array
	local ptrCurrent	as byte ptr
	local ptrBuffer		as byte ptr
	local nCurrent		as int
	local nPrevious		as int
	local nNext			as int
	local nI			as dword
	local nLen			as dword
	local nCurStart		as dword
	local cLine			as string

	nLen				:= SLen( cString )
	ptrBuffer			:= MemAlloc( nLen + 1 )
	Byte( ptrBuffer + nLen ) 	:= 0
	MemCopyString( ptrBuffer, cString, nLen )
	aResult				:= {}
	ptrCurrent			:= ptrBuffer
	nCurrent			:= 0
	nCurStart			:= 1
	nI					:= 1
	while nI < nLen
		nPrevious			:= nCurrent
		nCurrent			:= Int( Byte( ptrCurrent ) )
		if nI < nLen
			nNext				:= Int( Byte( ptrCurrent + 1 ) )
		else
			nNext				:= 0
		endif
		if nCurrent == 13 .and. nNext == 10		// ganz normales CRLF
			cLine				:= SubStr3( cString, nCurStart, nI - nCurStart )
			AAdd( aResult, cLine )
			ptrCurrent			+= 2
			nCurStart			:= nI + 2
			nI					+= 2
			loop
		endif
		if nCurrent == 13 .or. nCurrent == 10			// CR oder LF
			if ( nPrevious == 13 .or. nPrevious == 10 ) .and. nPrevious !=
nCurrent
				// vorheriges Zeichen war auch CR bzw. LF, aber ungleich, also
ignorieren
				nCurStart			:= nI + 1
				++ptrCurrent
				++nI
				loop
			endif
			cLine				:= SubStr3( cString, nCurStart, nI - nCurStart )
			AAdd( aResult, cLine )
			nCurStart			:= nI + 1
		endif
		++ptrCurrent
		++nI
	end

	if nCurStart > 0 .and. nCurStart <= nLen 	//  nCurStart > 0 .and.
nCurStart < nLen
		cLine				:= SubStr3( cString, nCurStart, nLen - nCurStart + 1 )
		AAdd( aResult, cLine )
	endif
	MemFree( ptrBuffer )

	return aResult    
	
function String2Array( cList as string, cDelimiter as string ) as array
//p String in Array umsetzen
//s
	local nPos          as dword
	local nStart		as dword
	local nLen			as dword
	local aList		    as array
	local nLines		as dword
	local cZeile		as string

	if SLen( cDelimiter ) == 0
		cDelimiter := ","
	endif
	aList		:= {}
	nStart		:= 1
	nLen		:= SLen( cDelimiter )
	nLines		:= 0

	while ( nPos := At3( cDelimiter, cList, nStart - 1 ) ) > 0
		cZeile		:= Trim( SubStr3( cList, nStart, nPos - nStart ) )
		nStart		:= nPos + nLen
		AAdd( aList, cZeile )
		++nLines
		if nLines % 100 == 0
			ApplicationExec( EXECWHILEEVENT )
		endif
	end
	AAdd( aList, Trim( SubStr2( cList, nStart ) ) )

	return aList  




-- 

Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Memoline replaces tabs with spaces? "Grzegorz R." <ramotny64@gmail.com> - 2021-11-15 06:53 -0800
  Re: Memoline replaces tabs with spaces? "Wolfgang Riedmann" <wriedmann@gmail.com> - 2021-11-16 07:01 +0100

csiph-web