Re: [Vala] Printing Unicode Characters



Emad Al-Bloushi wrote:
Dears,

I have made this sample and I want to post it in GNOME wiki so do you
recommend any change ?

You can avoid code duplication by pulling the character printing out of
the switch cases. And you should use 'unowned' instead of 'weak' if you
want to avoid string copying. 'weak' is intended only for breaking
reference cycles since some Vala versions.


Best regards,

Frederik
void main() {

  string unicode_string = "1234567890 ١٢٣٤٥٦٧٨٩۰ ABCDEFGHIJKLMNOPQRSTUVWXYZ 
abcdefghijklmnopqrstuvwxyz أبتةثجحخدذرزسشصضطظعغفقكلمنهوي";

  for (unowned string s = unicode_string; s.get_char ()!=0 ; s = s.next_char ()) {

    unichar unicode_character = s.get_char ();

    UnicodeType unicode_character_type = unicode_character.type ();

    stderr.printf("'%s' is ", new StringBuilder().append_unichar(unicode_character).str);

    switch (unicode_character_type) {

      case unicode_character_type.UPPERCASE_LETTER:
        stderr.printf("UPPERCASE_LETTER\n");
        break;

      case unicode_character_type.LOWERCASE_LETTER:
        stderr.printf("LOWERCASE_LETTER\n");
        break;

      case unicode_character_type.OTHER_LETTER:
        stderr.printf("OTHER_LETTER\n");
        break;

      case unicode_character_type.DECIMAL_NUMBER:
        stderr.printf("OTHER_NUMBER\n");
        break;

      case unicode_character_type.SPACE_SEPARATOR:
        stderr.printf("SPACE_SEPARATOR\n");
        break;
    }
  }
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]