From: | Nilgün Belma Bugüner <nilgun(at)superonline(dot)com> |
---|---|
To: | pgsql-tr-genel(at)postgresql(dot)org |
Subject: | Re: PostgreSQL 8.1 Beta + Windows + Unicode |
Date: | 2005-10-19 22:56:23 |
Message-ID: | 200510200156.23779.nilgun@superonline.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-tr-genel |
Selam,
Çar 19 Eki 2005 22:51 sularında, Volkan YAZICI şunları yazmıştı:
> Merhaba,
>
> On 10/17/05, Devrim GUNDUZ <devrim(at)gunduz(dot)org> wrote:
> > Magnus sıralama işlemini yapmak için utf-16'ya çevirim yapan ve sonra
> > geriye çeviren bir kod yazmıştı ve bu şekilde sorun çözüldü.
>
> Bir kaç gündür karakter boyu değişimi (up/downcasing) üzerine cımbızla
> saç yoluyorum. (Evet Nilgün Hanım, GNU C Library Manual'ın başlığında
> String ve Character kelimeleri geçen tüm bölümlerini okudum.)
Okuyunca olur sandım, pardon. :-) (Kişi herkesi kendi gibi bilirmiş).
Aşağıda hemen yazdığım bir kod var (Parçalarını size yollamıştım,
birleştirmeniz yetecekti.) Girdiyi komut satırından alıyor; örneğin,
koda updown.c dersek,
./updown İİİ
komutu
iİİ
diye bir çıktı veriyor.
Siz amacınıza uygun olarak geliştirirsiniz.
Çalışan bir örnek elinizde olsun diye yazdım.
------------------
/*
Copyright © 2005 Nilgün Belma Bugüner
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <wchar.h>
#include <wctype.h>
#include <string.h>
#include <limits.h>
/* Bir çokbaytlı karakter dizisindeki karakter sayısını bulur. */
size_t
mbstrlen (const char *string) {
char *t;
size_t result = 0;
mbstate_t state;
memset (&state, '\0', sizeof (state));
t = strdupa (string);
while (*t) {
t += mbrlen(t, MB_LEN_MAX, &state);
result++;
}
return result;
}
/* Bir geniş karakterli dizgenin bayt sayısını bulur. */
size_t
wcstrlen (wchar_t *string)
{
wchar_t *t;
char *mbs;
size_t result = 0;
mbstate_t state;
memset (&state, '\0', sizeof (state));
mbs = alloca (MB_LEN_MAX + 1);
t = string; result = 0;
while (*t) {
result += wcrtomb(mbs, *t, &state);
t++;
}
return result;
}
/* Geniş karakterli dizgeyi çokbaytlı dizgeye dönüştürüp basar */
void
print_wcs (const wchar_t *wbuf)
{
char *buf;
mbstate_t state;
int len = wcstrlen((wchar_t *)wbuf);
memset (&state, '\0', sizeof (state));
buf = alloca (len + 1);
memset (buf, '\0', len + 1);
wcsrtombs (buf, &wbuf, len, &state);
fputs(buf, stdout);
}
/* Çokbaytlı dizgeyi geniş karakterli dizgeye dönüştürür. */
wchar_t *
mbs2ws (const char *buf)
{
mbstate_t state;
wchar_t *wbuf;
int len;
memset (&state, '\0', sizeof (state));
len = mbstrlen (buf);
wbuf = (wchar_t *) malloc (len * sizeof(wchar_t) + 1);
mbsrtowcs (wbuf, &buf, len, &state);
return wbuf;
}
int
main(int argc, char *argv[])
{
wchar_t *wbuf;
wint_t wc;
/* Sistem yerelinin tr_TR.utf-8 olduğunu varsayıyoruz.
* Aksi takdirde bu kod bilhassa i/ı için doğru çalışmayacaktır.
*/
setlocale (LC_ALL, "");
/* Girdiyi, komut satırından okuyacağız.
* Gerçeğe uygun olsun :-)
*/
/* Çokbaytlı dizgeyi geniş karakterli dizgeye dönüştürelim */
wbuf = mbs2ws (argv[1]);
/* Girdinin bir dizge olduğunu varsayıyoruz.
* Sadece ilk karakteri dönüştürmekle yetineceğiz.
*/
wc = (wint_t) wbuf[0];
wbuf[0] = (wchar_t) towlower(wc); /* Küçük harfe dönüştürelim */
/* Sonucu çokbaytlı dizgeye dönüştürüp çıktılayalım. */
print_wcs(wbuf);
puts("");
free (wbuf);
return 0;
}
---------------------
Esen kalın,
Nilgün
From | Date | Subject | |
---|---|---|---|
Next Message | Volkan YAZICI | 2005-10-20 07:31:28 | Re: PostgreSQL 8.1 Beta + Windows + Unicode |
Previous Message | Volkan YAZICI | 2005-10-19 19:51:51 | Re: PostgreSQL 8.1 Beta + Windows + Unicode |