File: normalize.m

package info (click to toggle)
gnustep-corebase 0.1.1%2B20230710-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,608 kB
  • sloc: ansic: 25,359; objc: 4,347; cpp: 75; xml: 49; makefile: 24; sh: 7
file content (39 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
#include "CoreFoundation/CFString.h"
#include "../CFTesting.h"
#import <Foundation/NSString.h>
#include <string.h>

int main (void)
{
  // Letter 'Å'
  UniChar notNormalized[] = { 0x212B, 0 };
  UniChar normalized[] = { 0x0041, 0x030A, 0 };
  CFMutableStringRef mut;
  UniChar* processed;
  NSMutableString* nsmut;

  mut = CFStringCreateMutable (NULL, 0);
  CFStringAppendCharacters (mut, notNormalized, 1);

  CFStringNormalize(mut, kCFStringNormalizationFormD);
  processed = CFStringGetCharactersPtr(mut);

  printf("first char: %04x\n", *processed);

  PASS_CF (memcmp(processed, normalized, 4) == 0,
    "CFStringNormalize works");
  CFRelease(mut);

  nsmut = [[NSString stringWithCharacters: notNormalized
                                   length: 1] mutableCopy];
  CFStringNormalize((CFMutableStringRef) nsmut, kCFStringNormalizationFormD);

  PASS_CF ([nsmut length] == 2, "Correct char count");
  PASS_CF ([nsmut characterAtIndex: 0] == normalized[0],
    "CFStringNormalize works on an NSString");

  [nsmut release];

  return 0;
}