Click here to Skip to main content
13,052,558 members (62,751 online)
Click here to Skip to main content

Stats

25.6K views
28 bookmarked
Posted 12 Apr 2016

Linq-To-XML Style of Node Creation for C++

, 12 Apr 2016
Linq-To-XML Node Creation for Native C++
BuildProcessTemplates
Elmax.vsmdi
ElmaxNet
Properties
Elmax
Elmax.vcxproj.user
StringUtils
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
TryoutNet
Properties
Tryout
res
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Elmax-ver089
Elmax.vsmdi
Elmax
Elmax.vcxproj.user
StringUtils
ElmaxNet
Properties
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout
res
Tryout.ico
Tryout.vcxproj.user
TryoutNet
Properties
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout.ico
Tryout.vcxproj.user
Latest version have UTF-8 support! Internally it is still stored as unicode.


Notes for using Unicode file class
===================================
The buffer length required by some functions is in terms of wide-characters, not bytes
Example, for writing string of L"Hello", you specify 5, not 10.

==========================
If you specify zero as the buffer length for write functions, it will treat the string to be
written as null terminated.

For Read() function, you must specify the buffer length, except for ReadLine()
You must pass a null pointer to Read() and ReadLine().
You must delete the array returned by Read() and ReadLine() yourself.

==========================
Please use binary mode, when opening unicode file.
Please use text mode, when opening UTF-8 file.

example,

CUnicodeFile uf;
// open for writing
bool bRet = uf.Open( _T("D:\\test.txt"), _T("wb") );

// open for appending
//bool bRet = uf.Open( _T("D:\\test.txt"), _T("ab") );

if( bRet )
{
	uf.WriteLine( _T("Thank god is friday!") );
	...
}

==========================
Call IsUnicodeFile() immediately after opening to determine it is a unicode file
before proceeding.

==========================
Before using ReadLine(), you must call ReadAll() once;

CUnicodeFile uf;
bool bRet = uf.Open( "D:\\uc.txt", "rb" );

if( bRet )
{	
	uf.ReadAll();

	wchar_t *pwchar = 0;
	int nBufLen = 0;

	CString str;
	while( uf.ReadLine( pwchar, nBufLen ) )
	{
		if( pwchar )
		{
			// Do your stuff here			

			delete [] pwchar;
			pwchar = 0;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Cake Processor
Software Developer (Senior)
United States United States

Semi-retired from writing articles but may contribute tips from time to time.



IT Certifications


  • IT Infrastructure Library Foundational (ITIL v3)

  • Scrum Alliance Certified Scrum Master (CSM)

  • Certified Secure Software Lifecycle Professional (CSSLP)


You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 12 Apr 2016
Article Copyright 2016 by Cake Processor
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid