Difference between revisions of "MB ElementCount"

From WikiPrizm
Jump to navigationJump to search
(This function should not modify the string, so it should it should take a const pointer. Also removed unneeded casts to (char*).)
Line 3: Line 3:
 
| header = fxcg/system.h
 
| header = fxcg/system.h
 
| index = 0x1163
 
| index = 0x1163
| signature = int MB_ElementCount(char* buf)
+
| signature = int MB_ElementCount(const char* buf)
 
| synopsis = Counts the number of characters, as printed on screen, of a [[Multi-byte_strings|multi-byte string]].
 
| synopsis = Counts the number of characters, as printed on screen, of a [[Multi-byte_strings|multi-byte string]].
 
| parameters = * '''buf''' - pointer to the string to measure.
 
| parameters = * '''buf''' - pointer to the string to measure.
Line 10: Line 10:
 
  <nowiki>
 
  <nowiki>
 
char MBstring[10];
 
char MBstring[10];
strcpy(MBstring, (char*)"\xe6\x92\xe6\x93\xe6\xa5");
+
strcpy(MBstring, "\xe6\x92\xe6\x93\xe6\xa5");
 
int bytelen = strlen(MBstring);
 
int bytelen = strlen(MBstring);
 
// bytelen has a value of 6
 
// bytelen has a value of 6
Line 24: Line 24:
 
  <nowiki>
 
  <nowiki>
 
char MBstring[10];
 
char MBstring[10];
strcpy(MBstring, (char*)"Empty box: \xe6\xa5");
+
strcpy(MBstring, "Empty box: \xe6\xa5");
 
int bytelen = strlen(MBstring);
 
int bytelen = strlen(MBstring);
 
// bytelen has a value of 13
 
// bytelen has a value of 13

Revision as of 11:25, 14 February 2015


Synopsis

Header: fxcg/system.h
Syscall index: 0x1163
Function signature: int MB_ElementCount(const char* buf)

Counts the number of characters, as printed on screen, of a multi-byte string.

Parameters

  • buf - pointer to the string to measure.

Returns

The number of characters in the string, as printed by multi-byte-aware syscalls.

Example

The following example shows how a multi-byte string can take a memory space that's twice as large as the number of printed characters, and demonstrates how to count both size in bytes and graphical size:

char MBstring[10];
strcpy(MBstring, "\xe6\x92\xe6\x93\xe6\xa5");
int bytelen = strlen(MBstring);
// bytelen has a value of 6
int elemlen = MB_ElementCount(MBstring);
// elemlen has a value of 3

locate_OS(2,3);
Print_OS(MBstring, 0, 0); // will print three symbols on screen: an arrow up, an arrow down and a square.

Another example, which mixes standard and multi-byte characters:

char MBstring[10];
strcpy(MBstring, "Empty box: \xe6\xa5");
int bytelen = strlen(MBstring);
// bytelen has a value of 13
int elemlen = MB_ElementCount(MBstring);
// elemlen has a value of 12

locate_OS(2,3);
Print_OS(MBstring, 0, 0); // will print "Empty box: " followed by a square.