Unicode FileRead: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author and download links, and changed format of some pages.)
m (Updated author links.)
Line 1: Line 1:
{|align=right
|<small>Author: [[{{ns:2}}:lob|lob]] ([[{{ns:3}}:lob|talk]], [[{{ns:-1}}:Contributions/lob|contrib]])</small>
|}
<br style="clear:both;">
== Description ==
== Description ==
Read Unicode Files.
Read Unicode Files.
Line 55: Line 59:
done:
done:
</highlight-nsis>
</highlight-nsis>
Page author: [[User:lob|lob]]

Revision as of 03:05, 30 April 2005

Author: lob (talk, contrib)


Description

Read Unicode Files. The Function is very similar to the built in FileRead function. It reads in an ASCII Unicode text files by line. Note that multi byte characters are not read correctly and characters with more than two bytes throw the whole line if not the whole file off.

The Function

Function "FileReadUnicode"
	Pop $0 ; handle
	Push $1
	Push $2
	Push $3
	Push $4
 
	IntOp $4 0 + 0
	IntOp $3 0 + 0
	StrCpy $1 ""
	SetErrorLevel 0
read:	
	FileReadByte $0 $2
	IntCmp $4 0 0 skip skip
	IntCmp $2 0x0a skip 0 0 
	IntCmp $2 0x0d readsecondhalf 0 0 
	IntCmp $2 0 done 0 0
	IntFmt $2 "%c" $2
	StrCpy $1 "$1$2"
skip:	
	IntOp $4 $4 + 1
	IntOp $4 $4 % 2
	Goto read
readsecondhalf:	
	FileReadByte $0 $2
done:	
	Pop $4
	Pop $3
	Pop $2
	Push $1
	Exch 
	Pop $1
FunctionEnd

Sample Code

	FileOpen $R0 "c:\unicode.txt" r
	IfErrors done
read:	
	Push $R0
	Call FileReadUnicode
	Pop $R1
	IfErrors done
	MessageBox MB_OK "$R1" 
	Goto read
done: