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/ |