Skip to content

Commit

Permalink
- [satoriya-utf8] _ismbblead() -> _mbbc()
Browse files Browse the repository at this point in the history
  • Loading branch information
roytam1 committed Aug 27, 2008
1 parent 7215726 commit df5ee37
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 42 deletions.
5 changes: 3 additions & 2 deletions satoriya-utf8/_/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,12 @@ BOOL GetFileSize( LPCSTR szFileName, DWORD* pdwSize ) {
}

// 文字列中から指定の1byte文字が最後に出現する位置を返す。
#include <mbctype.h> // for _ismbblead()
//#include <mbctype.h> // for _ismbblead()
#include "Utilities.h" // for _mbbc()
template<class T>
inline T* FindFinalChar(T* start, T c) {
T* last=NULL;
for (T* p=start; *p ; p+=_ismbblead(*p)?2:1)
for (T* p=start; *p ; p+=_mbbc(*p))
if (*p==c)
last=p;
return last;
Expand Down
12 changes: 6 additions & 6 deletions satoriya-utf8/_/TextPositionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ void TextPositionManager::Home() {

// 行末と禁則を考慮して、改行処理。
void TextPositionManager::Before(const char* p) {
int len = _ismbblead(*p) ? 2 : 1;
int len = _mbbc(*p);

const char kinsoku[] = "!?。、";
if ( len == 2 )
for ( const char* pk=kinsoku ; *pk!='\0' ; pk+=2 )
if ( strncmp(p, pk, 2) == 0 )
if ( len > 1 )
for ( const char* pk=kinsoku ; *pk!='\0' ; pk+=3 )
if ( strncmp(p, pk, 3) == 0 )
return;

if ( mPosition.x >= mFormat.w-2 ) // -2 は禁則予定部分
if ( mPosition.x >= mFormat.w-3 ) // -3 は禁則予定部分
Return();
}

Expand All @@ -66,7 +66,7 @@ CPoint TextPositionManager::Position(CSize iFontSize) {

// 文字位置をインクリメント。
int TextPositionManager::After(const char* p) {
int len = _ismbblead(*p) ? 2 : 1;
int len = _mbbc(*p);
mPosition.x += len;
return len;
}
Expand Down
8 changes: 4 additions & 4 deletions satoriya-utf8/_/calc.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "stltool.h"
#include "simple_stack.h"
#ifdef POSIX
//#ifdef POSIX
# include "Utilities.h"
#else
/*#else
# include <mbctype.h>
#endif
#endif*/

//////////DEBUG/////////////////////////
#ifdef _WINDOWS
Expand Down Expand Up @@ -120,7 +120,7 @@ static bool make_deque(const char*& p, deque<calc_element>& oDeque) {
break;
if ( check_operator(p) )
break;
p += _ismbblead(*p) ? 2 : 1;
p += _mbbc(*p);
}
if (p==start)
return false; // 被演算子が必要なのに、ない。
Expand Down
2 changes: 1 addition & 1 deletion satoriya-utf8/_/stltool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ void xor_filter(byte* ioArray, int iLength, byte iXorValue) {

const char* find_final_char(const char* str, char c) {
const char* last=NULL, *p=str;
for (;*p; p+=_ismbblead(*p)?2:1)
for (;*p; p+=_mbbc(*p))
if ( *p==c )
last=p;
return last;
Expand Down
33 changes: 19 additions & 14 deletions satoriya-utf8/_/vcout.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,35 @@
using namespace std;

#include <windows.h>
#include <mbctype.h> // for _ismbblead()
//#include <mbctype.h> // for _ismbblead()
#include "Utilities.h" // for _ismbblead()


class vc_debugstring_buf : public streambuf {
int knj; // 2byte文字の保持
char utf8[4]; // UTF-8文字の保持
int utflen,utfpos;
public:
vc_debugstring_buf() : knj(0) {}
virtual int overflow(int c=EOF) {
char buf[3];
if (knj != 0) {
// 2byte文字の2byte目
buf[0] = (char)knj;
buf[1] = (char)c;
buf[2] = '\0';
::OutputDebugString(buf);
knj = 0;
if (utflen == 1 && utfpos) {
// UTF-8文字の最後
utf8[++utfpos] = c;
::OutputDebugString(utf8);
utflen = utfpos = 0;
}
else if ( _ismbblead(c) ) {
knj = c;
utflen = _mbbc(c) - 1;
utfpos = 0;
utf8[utfpos] = c;
}
else if ( _ismbbtail(c) ) {
--utflen;
utf8[++utfpos] = c;
}
else {
buf[0] = (char)c;
buf[1] = '\0';
::OutputDebugString(buf);
utf8[0] = (char)c;
utf8[1] = '\0';
::OutputDebugString(utf8);
}
return c;
}
Expand Down
2 changes: 1 addition & 1 deletion satoriya-utf8/satori/SakuraScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void sakura_script_parts::unserialize(string i_script)
{
++p; // エスケープされた]
}
p += _ismbblead(*p) ? 2 : 1;
p += _mbbc(*p);
}
option.assign(start, p++ - start);
}
Expand Down
4 changes: 2 additions & 2 deletions satoriya-utf8/satori/satoriTranslate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ bool Satori::Translate(string& ioScript) {
}
}
}
if ( c < n && _ismbblead(i->at(c)) ) {
++c;
if ( c < n ) {
c += _mbbc(i->at(c));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions satoriya-utf8/satori/satori_Kakko.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ void add_characters(const char* p, int& chars_spoken) {
if (p[0]=='\\' && p[1]==']') // エスケープされた]
++p;
else
p += _ismbblead(*p) ? 2 : 1;
p += _mbbc(*p);
}
}
else {
int len = _ismbblead(*p) ? 2 : 1;
int len = _mbbc(*p);
p += len;
chars_spoken += len;
}
Expand Down
18 changes: 8 additions & 10 deletions satoriya-utf8/satori/ssu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static string zen2han_internal(string &str,unsigned int flag = 0xffffU);
// 半角/全角を同等に扱った上で文字長を返す
int sjis_strlen(const char* p) {
int n=0;
for (int i=0 ; p[i] != '\0' ; i += _ismbblead(p[i]) ? 2 : 1 )
for (int i=0 ; p[i] != '\0' ; i += _mbbc(p[i]))
++n;
return n;
}
Expand All @@ -124,7 +124,7 @@ const char* sjis_at(const char* p, int n) {
for (int i=0 ; i<n ; ++i) {
if ( *p == '\0' )
return NULL;
p += _ismbblead(*p) ? 2 : 1;
p += _mbbc(*p);
}
return p;
}
Expand Down Expand Up @@ -285,11 +285,9 @@ string sprintf(deque<string>& iArguments) {
continue;
}
}
if ( _ismbblead(*p) ) {
s << *p++; s << *p++;
} else {
int lenp = 0; lenp = _mbbc(*p);
for(int q = 0;q < lenp; q++)
s << *p++;
}
}
return s.str();
}
Expand Down Expand Up @@ -724,7 +722,7 @@ SRV _hira2kata(deque<string>& iArguments, deque<string>& oValues) {
return SRV(400, "引数の個数が正しくありません。");

string& str=iArguments[0];
for (int i=0 ; str[i]!='\0' ; i+=_ismbblead(str[i])?2:1) {
for (int i=0 ; str[i]!='\0' ; i+=_mbbc(str[i])) {
for (int j=0 ; j<sizeof(hira) ; j+=2) {
if ( str[i]==hira[j] && str[i+1]==hira[j+1] ) {
str[i]=kata[j];
Expand All @@ -740,7 +738,7 @@ SRV _kata2hira(deque<string>& iArguments, deque<string>& oValues) {
return SRV(400, "引数の個数が正しくありません。");

string& str=iArguments[0];
for (int i=0 ; str[i]!='\0' ; i+=_ismbblead(str[i])?2:1) {
for (int i=0 ; str[i]!='\0' ; i+=_mbbc(str[i])) {
for (int j=0 ; j<sizeof(hira) ; j+=2) {
if ( str[i]==kata[j] && str[i+1]==kata[j+1] ) {
str[i]=hira[j];
Expand All @@ -764,7 +762,7 @@ SRV _reverse(deque<string>& iArguments, deque<string>& oValues) {
string r;
const char* p = iArguments[0].c_str();
while (*p != '\0') {
const int len = _ismbblead(*p)?2:1;
const int len = _mbbc(*p);
r = string(p, len) + r;
p += len;
}
Expand All @@ -776,7 +774,7 @@ SRV _at(deque<string>& iArguments, deque<string>& oValues) {

if ( iArguments.size()==2 ) {
const char* p = sjis_at(iArguments.at(0).c_str(), zen2int(iArguments.at(1)));
return (p==NULL || *p=='\0') ? "" : string(p, _ismbblead(*p)?2:1);
return (p==NULL || *p=='\0') ? "" : string(p, _mbbc(*p));
}
//else if ( iArguments.size()==3 ) {
//}
Expand Down

0 comments on commit df5ee37

Please sign in to comment.