All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bridj.objc.FoundationLibrary Maven / Gradle / Ivy

There is a newer version: 0.7.0
Show newest version
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.bridj.objc;

import java.nio.charset.Charset;
import java.util.Map;
import org.bridj.BridJ;
import org.bridj.CRuntime;
import org.bridj.Pointer;
import static org.bridj.Pointer.*;
import org.bridj.Pointer.StringType;
import org.bridj.ann.Library;
import org.bridj.ann.Ptr;

@Library("Foundation")
@org.bridj.ann.Runtime(CRuntime.class)
public class FoundationLibrary {
    static {
        BridJ.register();
    }
    
    public static final int 
        kCFStringEncodingASCII = 0x0600,
        kCFStringEncodingUnicode = 0x0100,
        kCFStringEncodingUTF8 = 0x08000100;

    public static native Pointer CFStringCreateWithBytes(Pointer alloc, Pointer bytes, @Ptr long  numBytes, int encoding, boolean isExternalRepresentation);
    
    
    public static Pointer pointerToNSString(String s) {
        Pointer p = Pointer.pointerToString(s, StringType.C, Charset.forName("utf-8"));
        assert p != null;
        Pointer ps = CFStringCreateWithBytes(null, p, p.getValidBytes() - 1 /* remove the trailing NULL */, kCFStringEncodingUTF8, false);
        assert ps != null;
        return ps;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy