Discussion:
[dart-misc] How to manually convert between Latin-5 and Unicode code points?
Niyazi Toros
2018-07-03 07:17:50 UTC
Permalink
I have socket connection and I can get data from my socket. The data
encoded as Latin-5.


_xCustomerName = 

 // will get data from socket like: “879255:_:NÝYAZÝ
TOROS”


_xCustomerName.replaceAll(new RegExp(r'Ý'), 'İ');


An seems it doesnt replace the 'Ý' to ‘İ’.



How to manually convert between Latin-5 and Unicode code points?
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/357899a5-bd79-4cc2-8393-559327c0c1de%40dartlang.org.
'William Hesse' via Dart Misc
2018-07-03 07:43:21 UTC
Permalink
The String.replaceAll function does not modify the string it is called on,
it returns a new String object with the modifications.

The best way to change a string from Latin5 to Unicode would be to
implement a Latin5 encoder/decoder using the classes in dart:convert.
This would map from a byte string to a String. It is a bit difficult,
though.
Post by Niyazi Toros
I have socket connection and I can get data from my socket. The data
encoded as Latin-5.
_xCustomerName = 

 // will get data from socket like: “879255:_:NÝYAZÝ
TOROS”
_xCustomerName.replaceAll(new RegExp(r'Ý'), 'İ');
An seems it doesnt replace the 'Ý' to ‘İ’.
How to manually convert between Latin-5 and Unicode code points?
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/a/dartlang.org/d/msgid/misc/357899a5-bd79-4cc2-8393-559327c0c1de%40dartlang.org
<https://groups.google.com/a/dartlang.org/d/msgid/misc/357899a5-bd79-4cc2-8393-559327c0c1de%40dartlang.org?utm_medium=email&utm_source=footer>
.
--
William Hesse
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CAMQL4kjzYUzgZWxnuHdoEtBH2DU5rLNMh0VHujT0e2CdcV_UCw%40mail.gmail.com.
Niyazi Toros
2018-07-03 07:53:28 UTC
Permalink
Thanks William, Where I can get information so I can start implementing
Latin5 encoder/decoder.
I need some example that implements Latin? encoder/decoder. It seems Dart
only supports Latin1.

I need to write my own classes, but I don't know where to start.

And secondly does dart has any character replacement option like other
language?
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/34d738a8-2dc0-4683-9507-4d6606d26029%40dartlang.org.
Niyazi Toros
2018-07-03 08:39:16 UTC
Permalink
I know the Latin 1 and Latin 5 differences. So I just create a switch loop
and now I can get the character that I wanted.

So the “879255:_:NÝYAZÝ TOROS” becomes “879255:_:NİYAZİ TOROS”

_xCustomerName.runes.forEach((int rune) {
var character = new String.fromCharCode(rune);
switch (character) {
case 'Ð':
character = 'Ğ';
break;
case 'Ý':
character = 'Ä°';
break;
case 'Þ':
character = 'Ş';
break;
case 'ð':
character = 'ğ';
break;
case 'Ü':
character = 'ı';
break;
case 'ß':
character = 'ş';
break;
}

_xCustomerNameTurkish = _xCustomerNameTurkish + character;
});
print(_xCustomerNameTurkish);
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/182d1b43-097a-4283-8724-b2bcb27cc3bd%40dartlang.org.
'William Hesse' via Dart Misc
2018-07-03 08:55:33 UTC
Permalink
That is a good, simple solution. You could use a StringBuffer to be more
efficient, so:

var correctName = new StringBuffer();

(in loop)
correctName.write(character);

(at end)
var turkishName = correctName.toString();


You could also use ReplaceAll:
correctName = correctName
.replaceAll( 'ß', 'ş')
.replaceAll( 'Ü', 'ı')
.replaceAll( 'ð', 'ğ')
...
Post by Niyazi Toros
I know the Latin 1 and Latin 5 differences. So I just create a switch loop
and now I can get the character that I wanted.
So the “879255:_:NÝYAZÝ TOROS” becomes “879255:_:NİYAZİ TOROS”
_xCustomerName.runes.forEach((int rune) {
var character = new String.fromCharCode(rune);
switch (character) {
character = 'Ğ';
break;
character = 'Ä°';
break;
character = 'Ş';
break;
character = 'ğ';
break;
character = 'ı';
break;
character = 'ş';
break;
}
_xCustomerNameTurkish = _xCustomerNameTurkish + character;
});
print(_xCustomerNameTurkish);
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/a/dartlang.org/d/msgid/misc/182d1b43-097a-4283-8724-b2bcb27cc3bd%40dartlang.org
<https://groups.google.com/a/dartlang.org/d/msgid/misc/182d1b43-097a-4283-8724-b2bcb27cc3bd%40dartlang.org?utm_medium=email&utm_source=footer>
.
--
William Hesse
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CAMQL4khN%3D_HLNMxfnqv%3DRfX63B_1Fe09%2BSxZf4Q-pDEEYP%3Du1Q%40mail.gmail.com.
Niyazi Toros
2018-07-03 09:01:42 UTC
Permalink
Thanks William, I will do it. Kind Regards
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/17bd4228-23ca-4d1d-b348-28e83155b311%40dartlang.org.
'William Hesse' via Dart Misc
2018-07-03 09:06:43 UTC
Permalink
Also, since you are only changing characters in the basic plane (16-bit
chars), you could just loop over the code points as characters:
The only different between this and runes.forEach and turning code points
to strings is that you would get non-basic plane characters
as two surrogate pair characters, which your loop passes through unchanged.

for (int i=0; i < oldName.length; ++i) {
String char = oldName[i];
switch (char) {
...
Post by Niyazi Toros
Thanks William, I will do it. Kind Regards
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/a/dartlang.org/d/msgid/misc/17bd4228-23ca-4d1d-b348-28e83155b311%40dartlang.org
<https://groups.google.com/a/dartlang.org/d/msgid/misc/17bd4228-23ca-4d1d-b348-28e83155b311%40dartlang.org?utm_medium=email&utm_source=footer>
.
--
William Hesse
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CAMQL4kjdvm5GYaaFAU%3DwXyO9FZAyw2acvRCr4p%2BK%3De8Y32KuYQ%40mail.gmail.com.
Niyazi Toros
2018-07-03 09:13:01 UTC
Permalink
Thanks William, I will try it.
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/971baea5-cce4-4fc8-b636-b48405efa27b%40dartlang.org.
Continue reading on narkive:
Loading...