This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: cpplib utf8, status?


Joseph S. Myers said:     (by the date of Mon, 26 Apr 2010 14:15:06 +0000 (UTC))

> > I suppose that "raw/real" UTF-8 will not work ;)
> > So how do I express UCN in the code?
> 
> By using the \uNNNN or \UNNNNNNNN syntax.  For example, pipe your code 
> through
> 
> perl -pe 'BEGIN { binmode STDIN, ":utf8"; } s/(.)/ord($1) < 128 ? $1 : sprintf("\\U%08x", ord($1))/ge;'


Wow! It works. Thanks a lot! Unbelievable!

//file UCN_almost_UTF8_identifiers.cpp

#include<iostream>
int main()
{
	double Î_çåvelocity(0);
	std::cout << "Î_vçåelocity= " << Î_çåvelocity << "\n";
}

// with following makefile:

UCN_almost_UTF8_identifiers:UCN_almost_UTF8_identifiers.cpp
	/home/janek/bin/to_UCN.sh UCN_almost_UTF8_identifiers.cpp
	g++ -fextended-identifiers -o UCN_almost_UTF8_identifiers /tmp/UCN_almost_UTF8_identifiers.cpp

//and the helper script: to_UCN.sh:

#!/bin/bash
cat $1 | perl -pe 'BEGIN { binmode STDIN, ":utf8"; } s/(.)/ord($1) < 128 ? $1 : sprintf("\\U%08x", ord($1))/ge;' > /tmp/$1


I'm happy that now, for quick testing purposes, I can use UTF8 symbols
for variable names in  C++, even though the code is totally not
portable, it will work locally, and will help me a lot in writing
physical stuff.

-- 
Janek Kozicki                               http://janek.kozicki.pl/  |


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]