Changeset 331 for EcnlProtoTool/trunk/prototool/src/arduino.c
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/prototool/src/arduino.c
r321 r331 4 4 #include <stdio.h> 5 5 #include <fcntl.h> 6 #include <sys/stat.h> 6 7 #include "../llbruby.h" 7 8 … … 544 545 return 0; 545 546 } 547 548 unsigned int Utf8_to_Utf16(const char *src, int *code_size) 549 { 550 int i; 551 unsigned int uc = 0; 552 unsigned char len = 0; 553 554 len = 0; 555 if ((src[0] & 0x80) == 0) { uc = src[0] & 0x7F; len = 0; } 556 else if ((src[0] & 0xE0) == 0xC0) { uc = src[0] & 0x1F; len = 1; } 557 else if ((src[0] & 0xF0) == 0xE0) { uc = src[0] & 0x0F; len = 2; } 558 else if ((src[0] & 0xF8) == 0xF0) { uc = src[0] & 0x07; len = 3; } 559 else if ((src[0] & 0xFC) == 0xF8) { uc = src[0] & 0x03; len = 4; } 560 else if ((src[0] & 0xFE) == 0xFC) { uc = src[0] & 0x01; len = 5; } 561 562 i = 1; 563 while ((i <= len) && ((src[i] & 0xC0) == 0x80)) { 564 uc = (uc << 6) | (src[i] & 0x3F); 565 i++; 566 } 567 568 //消費文字数設定 569 *code_size = i; 570 571 //現状、2バイト限定 572 return uc; 573 } 574 575 int bs_char_count(char *str, int pos) 576 { 577 int num = 1, local_pos = pos; 578 char *c; 579 580 while (1) { 581 c = str + local_pos; 582 583 if ((*c & 0x80) != 0x80) 584 return num; 585 586 if (((*c & 0xE0) == 0xC0) && (num == 2)) { 587 return num; 588 } 589 else if (((*c & 0xF0) == 0xE0) && (num == 3)) { 590 return num; 591 } 592 else if (((*c & 0xF8) == 0xF0) && (num == 4)) { 593 return num; 594 } 595 else if (((*c & 0xFC) == 0xF8) && (num == 5)) { 596 return num; 597 } 598 else if (((*c & 0xFE) == 0xFC) && (num == 6)) { 599 return num; 600 } 601 else { 602 if (local_pos > 0) { 603 local_pos--; 604 num++; 605 } 606 else 607 return 0; 608 } 609 } 610 611 return 0; 612 }
Note:
See TracChangeset
for help on using the changeset viewer.