Recent

Author Topic: UnicodeToCP857  (Read 4572 times)

safa4141

  • Newbie
  • Posts: 3
UnicodeToCP857
« on: October 14, 2015, 11:39:38 am »
How can i convert string UnicodeToCP857 (MS-DOS Turkish) ??
Lazarus dosn't have this function. Please help me!

GetMem

  • Hero Member
  • *****
  • Posts: 3508
Re: UnicodeToCP857
« Reply #1 on: October 14, 2015, 02:07:15 pm »
Add  LConvEncoding to the uses clauses. Open LConvEncoding, take a look at how UTF8ToCP1254 and CP1254ToUTF8(non-dos turkish) is implemented. Do the same for CP857. Alternatively on windows you can do the conversion with WideCharToMultiByte and MultiByteToWideChar api, just don't forget to convert the result to UTF8.

sky_khan

  • Guest
Re: UnicodeToCP857
« Reply #2 on: October 14, 2015, 02:40:50 pm »
I had no job and nothing to do. I spent half an hour just for the sake of writing this  You should really have bought me a beer or something but whatever :)
(in Turkish:) İş yok güç yok. Sırf iş olsun diye yarım saat uğraştım şuna. Aslında bira falan ısmarlaman lazımdı bana ya hadi neyse :)

Code: Pascal  [Select]
  1. unit doscp857;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, LConvEncoding;
  9.  
  10. function UTF8ToCP857(const s:string):string; // Turkish
  11.  
  12. implementation
  13.  
  14.   function UnicodeToCP857(Unicode: cardinal): integer;
  15.   begin
  16.     case Unicode of
  17.     0..127: Result:=Unicode;
  18.     $00c7 : result:=$80 ;       //LATIN CAPITAL LETTER C WITH CEDILLA
  19.     $00fc : result:=$81 ;       //LATIN SMALL LETTER U WITH DIAERESIS
  20.     $00e9 : result:=$82 ;       //LATIN SMALL LETTER E WITH ACUTE
  21.     $00e2 : result:=$83 ;       //LATIN SMALL LETTER A WITH CIRCUMFLEX
  22.     $00e4 : result:=$84 ;       //LATIN SMALL LETTER A WITH DIAERESIS
  23.     $00e0 : result:=$85 ;       //LATIN SMALL LETTER A WITH GRAVE
  24.     $00e5 : result:=$86 ;       //LATIN SMALL LETTER A WITH RING ABOVE
  25.     $00e7 : result:=$87 ;       //LATIN SMALL LETTER C WITH CEDILLA
  26.     $00ea : result:=$88 ;       //LATIN SMALL LETTER E WITH CIRCUMFLEX
  27.     $00eb : result:=$89 ;       //LATIN SMALL LETTER E WITH DIAERESIS
  28.     $00e8 : result:=$8a ;       //LATIN SMALL LETTER E WITH GRAVE
  29.     $00ef : result:=$8b ;       //LATIN SMALL LETTER I WITH DIAERESIS
  30.     $00ee : result:=$8c ;       //LATIN SMALL LETTER I WITH CIRCUMFLEX
  31.     $0131 : result:=$8d ;       //LATIN SMALL LETTER DOTLESS I
  32.     $00c4 : result:=$8e ;       //LATIN CAPITAL LETTER A WITH DIAERESIS
  33.     $00c5 : result:=$8f ;       //LATIN CAPITAL LETTER A WITH RING ABOVE
  34.     $00c9 : result:=$90 ;       //LATIN CAPITAL LETTER E WITH ACUTE
  35.     $00e6 : result:=$91 ;       //LATIN SMALL LIGATURE AE
  36.     $00c6 : result:=$92 ;       //LATIN CAPITAL LIGATURE AE
  37.     $00f4 : result:=$93 ;       //LATIN SMALL LETTER O WITH CIRCUMFLEX
  38.     $00f6 : result:=$94 ;       //LATIN SMALL LETTER O WITH DIAERESIS
  39.     $00f2 : result:=$95 ;       //LATIN SMALL LETTER O WITH GRAVE
  40.     $00fb : result:=$96 ;       //LATIN SMALL LETTER U WITH CIRCUMFLEX
  41.     $00f9 : result:=$97 ;       //LATIN SMALL LETTER U WITH GRAVE
  42.     $0130 : result:=$98 ;       //LATIN CAPITAL LETTER I WITH DOT ABOVE
  43.     $00d6 : result:=$99 ;       //LATIN CAPITAL LETTER O WITH DIAERESIS
  44.     $00dc : result:=$9a ;       //LATIN CAPITAL LETTER U WITH DIAERESIS
  45.     $00f8 : result:=$9b ;       //LATIN SMALL LETTER O WITH STROKE
  46.     $00a3 : result:=$9c ;       //POUND SIGN
  47.     $00d8 : result:=$9d ;       //LATIN CAPITAL LETTER O WITH STROKE
  48.     $015e : result:=$9e ;       //LATIN CAPITAL LETTER S WITH CEDILLA
  49.     $015f : result:=$9f ;       //LATIN SMALL LETTER S WITH CEDILLA
  50.     $00e1 : result:=$a0 ;       //LATIN SMALL LETTER A WITH ACUTE
  51.     $00ed : result:=$a1 ;       //LATIN SMALL LETTER I WITH ACUTE
  52.     $00f3 : result:=$a2 ;       //LATIN SMALL LETTER O WITH ACUTE
  53.     $00fa : result:=$a3 ;       //LATIN SMALL LETTER U WITH ACUTE
  54.     $00f1 : result:=$a4 ;       //LATIN SMALL LETTER N WITH TILDE
  55.     $00d1 : result:=$a5 ;       //LATIN CAPITAL LETTER N WITH TILDE
  56.     $011e : result:=$a6 ;       //LATIN CAPITAL LETTER G WITH BREVE
  57.     $011f : result:=$a7 ;       //LATIN SMALL LETTER G WITH BREVE
  58.     $00bf : result:=$a8 ;       //INVERTED QUESTION MARK
  59.     $00ae : result:=$a9 ;       //REGISTERED SIGN
  60.     $00ac : result:=$aa ;       //NOT SIGN
  61.     $00bd : result:=$ab ;       //VULGAR FRACTION ONE HALF
  62.     $00bc : result:=$ac ;       //VULGAR FRACTION ONE QUARTER
  63.     $00a1 : result:=$ad ;       //INVERTED EXCLAMATION MARK
  64.     $00ab : result:=$ae ;       //LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
  65.     $00bb : result:=$af ;       //RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
  66.     $2591 : result:=$b0 ;       //LIGHT SHADE
  67.     $2592 : result:=$b1 ;       //MEDIUM SHADE
  68.     $2593 : result:=$b2 ;       //DARK SHADE
  69.     $2502 : result:=$b3 ;       //BOX DRAWINGS LIGHT VERTICAL
  70.     $2524 : result:=$b4 ;       //BOX DRAWINGS LIGHT VERTICAL AND LEFT
  71.     $00c1 : result:=$b5 ;       //LATIN CAPITAL LETTER A WITH ACUTE
  72.     $00c2 : result:=$b6 ;       //LATIN CAPITAL LETTER A WITH CIRCUMFLEX
  73.     $00c0 : result:=$b7 ;       //LATIN CAPITAL LETTER A WITH GRAVE
  74.     $00a9 : result:=$b8 ;       //COPYRIGHT SIGN
  75.     $2563 : result:=$b9 ;       //BOX DRAWINGS DOUBLE VERTICAL AND LEFT
  76.     $2551 : result:=$ba ;       //BOX DRAWINGS DOUBLE VERTICAL
  77.     $2557 : result:=$bb ;       //BOX DRAWINGS DOUBLE DOWN AND LEFT
  78.     $255d : result:=$bc ;       //BOX DRAWINGS DOUBLE UP AND LEFT
  79.     $00a2 : result:=$bd ;       //CENT SIGN
  80.     $00a5 : result:=$be ;       //YEN SIGN
  81.     $2510 : result:=$bf ;       //BOX DRAWINGS LIGHT DOWN AND LEFT
  82.     $2514 : result:=$c0 ;       //BOX DRAWINGS LIGHT UP AND RIGHT
  83.     $2534 : result:=$c1 ;       //BOX DRAWINGS LIGHT UP AND HORIZONTAL
  84.     $252c : result:=$c2 ;       //BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
  85.     $251c : result:=$c3 ;       //BOX DRAWINGS LIGHT VERTICAL AND RIGHT
  86.     $2500 : result:=$c4 ;       //BOX DRAWINGS LIGHT HORIZONTAL
  87.     $253c : result:=$c5 ;       //BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
  88.     $00e3 : result:=$c6 ;       //LATIN SMALL LETTER A WITH TILDE
  89.     $00c3 : result:=$c7 ;       //LATIN CAPITAL LETTER A WITH TILDE
  90.     $255a : result:=$c8 ;       //BOX DRAWINGS DOUBLE UP AND RIGHT
  91.     $2554 : result:=$c9 ;       //BOX DRAWINGS DOUBLE DOWN AND RIGHT
  92.     $2569 : result:=$ca ;       //BOX DRAWINGS DOUBLE UP AND HORIZONTAL
  93.     $2566 : result:=$cb ;       //BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
  94.     $2560 : result:=$cc ;       //BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
  95.     $2550 : result:=$cd ;       //BOX DRAWINGS DOUBLE HORIZONTAL
  96.     $256c : result:=$ce ;       //BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
  97.     $00a4 : result:=$cf ;       //CURRENCY SIGN
  98.     $00ba : result:=$d0 ;       //MASCULINE ORDINAL INDICATOR
  99.     $00aa : result:=$d1 ;       //FEMININE ORDINAL INDICATOR
  100.     $00ca : result:=$d2 ;       //LATIN CAPITAL LETTER E WITH CIRCUMFLEX
  101.     $00cb : result:=$d3 ;       //LATIN CAPITAL LETTER E WITH DIAERESIS
  102.     $00c8 : result:=$d4 ;       //LATIN CAPITAL LETTER E WITH GRAVE
  103.     $00cd : result:=$d6 ;       //LATIN CAPITAL LETTER I WITH ACUTE
  104.     $00ce : result:=$d7 ;       //LATIN CAPITAL LETTER I WITH CIRCUMFLEX
  105.     $00cf : result:=$d8 ;       //LATIN CAPITAL LETTER I WITH DIAERESIS
  106.     $2518 : result:=$d9 ;       //BOX DRAWINGS LIGHT UP AND LEFT
  107.     $250c : result:=$da ;       //BOX DRAWINGS LIGHT DOWN AND RIGHT
  108.     $2588 : result:=$db ;       //FULL BLOCK
  109.     $2584 : result:=$dc ;       //LOWER HALF BLOCK
  110.     $00a6 : result:=$dd ;       //BROKEN BAR
  111.     $00cc : result:=$de ;       //LATIN CAPITAL LETTER I WITH GRAVE
  112.     $2580 : result:=$df ;       //UPPER HALF BLOCK
  113.     $00d3 : result:=$e0 ;       //LATIN CAPITAL LETTER O WITH ACUTE
  114.     $00df : result:=$e1 ;       //LATIN SMALL LETTER SHARP S
  115.     $00d4 : result:=$e2 ;       //LATIN CAPITAL LETTER O WITH CIRCUMFLEX
  116.     $00d2 : result:=$e3 ;       //LATIN CAPITAL LETTER O WITH GRAVE
  117.     $00f5 : result:=$e4 ;       //LATIN SMALL LETTER O WITH TILDE
  118.     $00d5 : result:=$e5 ;       //LATIN CAPITAL LETTER O WITH TILDE
  119.     $00b5 : result:=$e6 ;       //MICRO SIGN
  120.     $00d7 : result:=$e8 ;       //MULTIPLICATION SIGN
  121.     $00da : result:=$e9 ;       //LATIN CAPITAL LETTER U WITH ACUTE
  122.     $00db : result:=$ea ;       //LATIN CAPITAL LETTER U WITH CIRCUMFLEX
  123.     $00d9 : result:=$eb ;       //LATIN CAPITAL LETTER U WITH GRAVE
  124.     $00ec : result:=$ec ;       //LATIN SMALL LETTER I WITH GRAVE
  125.     $00ff : result:=$ed ;       //LATIN SMALL LETTER Y WITH DIAERESIS
  126.     $00af : result:=$ee ;       //MACRON
  127.     $00b4 : result:=$ef ;       //ACUTE ACCENT
  128.     $00ad : result:=$f0 ;       //SOFT HYPHEN
  129.     $00b1 : result:=$f1 ;       //PLUS-MINUS SIGN
  130.     $00be : result:=$f3 ;       //VULGAR FRACTION THREE QUARTERS
  131.     $00b6 : result:=$f4 ;       //PILCROW SIGN
  132.     $00a7 : result:=$f5 ;       //SECTION SIGN
  133.     $00f7 : result:=$f6 ;       //DIVISION SIGN
  134.     $00b8 : result:=$f7 ;       //CEDILLA
  135.     $00b0 : result:=$f8 ;       //DEGREE SIGN
  136.     $00a8 : result:=$f9 ;       //DIAERESIS
  137.     $00b7 : result:=$fa ;       //MIDDLE DOT
  138.     $00b9 : result:=$fb ;       //SUPERSCRIPT ONE
  139.     $00b3 : result:=$fc ;       //SUPERSCRIPT THREE
  140.     $00b2 : result:=$fd ;       //SUPERSCRIPT TWO
  141.     $25a0 : result:=$fe ;       //BLACK SQUARE
  142.     $00a0 : result:=$ff ;       //NO-BREAK SPACE  end;
  143.     else result:=-1;
  144.   end;
  145. end;
  146.  
  147. function UTF8ToCP857(const s:string):string;
  148. begin
  149.   Result:=UTF8ToSingleByte(s,@UnicodeToCP857);
  150. end;
  151.  
  152. end.
  153.  
  154.  
« Last Edit: October 14, 2015, 02:42:59 pm by sky_khan »

safa4141

  • Newbie
  • Posts: 3
Re: UnicodeToCP857
« Reply #3 on: October 15, 2015, 11:50:07 am »
Allah senden razı olsun  :D Bira ısmarlayamam buradan belki ama çok dua edeceğim sana. Büyük bir dertten kurtardın beni. ;)
Durumun nedir bilmiyorum ama tecrübeli Delphi programcısı arıyoruz eğer ilgilenirsen ciddi anlamda görüşebiliriz. :)
Herşey için tekrar tşk. ederim. Allah ne muradın varsa tez zamanda gerçekleştirsin inş.