File: vt_normalize.m

package info (click to toggle)
mlterm 3.9.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,340 kB
  • sloc: ansic: 154,713; sh: 5,302; cpp: 2,953; objc: 2,776; java: 2,472; makefile: 2,445; perl: 1,674; xml: 44
file content (29 lines) | stat: -rw-r--r-- 672 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */

#ifdef __APPLE__

#include <CoreFoundation/CoreFoundation.h>

/* --- global functions --- */

int vt_normalize(UniChar* str, int num) {
  static CFMutableStringRef mutable_str;

  if (!mutable_str) {
    mutable_str = CFStringCreateMutable(kCFAllocatorDefault, 0);
  }

  CFStringAppendCharacters(mutable_str, str, num);
  CFStringNormalize(mutable_str, kCFStringNormalizationFormC);

  if ((num = CFStringGetLength(mutable_str)) == 1) {
    /* Normalized */
    CFStringGetCharacters(mutable_str, CFRangeMake(0, 1), str);
  }

  CFStringDelete(mutable_str, CFRangeMake(0, num));

  return num;
}

#endif