CFString.h (partway)
authorPHO <pho@cielonegro.org>
Mon, 18 Oct 2010 17:30:13 +0000 (02:30 +0900)
committerPHO <pho@cielonegro.org>
Mon, 18 Oct 2010 17:30:13 +0000 (02:30 +0900)
Bindings/CoreFoundation/CFString.hsc [new file with mode: 0644]
bindings-CoreFoundation.cabal
cbits/helper_CFString.c [new file with mode: 0644]

diff --git a/Bindings/CoreFoundation/CFString.hsc b/Bindings/CoreFoundation/CFString.hsc
new file mode 100644 (file)
index 0000000..ea41f9f
--- /dev/null
@@ -0,0 +1,159 @@
+#include <bindings.dsl.h>
+#include <CoreFoundation/CFString.h>
+
+module Bindings.CoreFoundation.CFString where
+#strict_import
+import Bindings.CoreFoundation.CFBase
+import Bindings.CoreFoundation.CFArray
+import Bindings.CoreFoundation.CFData
+import Bindings.CoreFoundation.CFDictionary
+import Bindings.CoreFoundation.CFCharacterSet
+import Bindings.CoreFoundation.CFLocale
+
+#integral_t CFStringEncoding
+#num kCFStringEncodingInvalidId
+#num kCFStringEncodingMacRoman
+#num kCFStringEncodingWindowsLatin1
+#num kCFStringEncodingISOLatin1
+#num kCFStringEncodingNextStepLatin
+#num kCFStringEncodingASCII
+#num kCFStringEncodingUnicode
+#num kCFStringEncodingUTF8
+#num kCFStringEncodingNonLossyASCII
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+#  num kCFStringEncodingUTF16
+#  num kCFStringEncodingUTF16BE
+#  num kCFStringEncodingUTF16LE
+#  num kCFStringEncodingUTF32
+#  num kCFStringEncodingUTF32BE
+#  num kCFStringEncodingUTF32LE
+#endif
+#synonym_t CFStringBuiltInEncodings, <CFStringEncoding>
+
+#ccall CFStringGetTypeID, IO <CFTypeID>
+
+-- NOTE: There's no way to import CFSTR(cStr) macro as it mentions
+-- builtin functions.
+
+#ccall CFStringCreateWithPascalString, <CFAllocatorRef> -> <ConstStr255Param> -> <CFStringEncoding> -> IO <CFStringRef>
+#ccall CFStringCreateWithCString     , <CFAllocatorRef> -> Ptr CChar -> <CFStringEncoding> -> IO <CFStringRef>
+#ccall CFStringCreateWithBytes       , <CFAllocatorRef> -> Ptr <UInt8> -> <CFIndex> -> <CFStringEncoding> -> <Boolean> -> IO <CFStringRef>
+#ccall CFStringCreateWithCharacters  , <CFAllocatorRef> -> Ptr <UniChar> -> <CFIndex> -> IO <CFStringRef>
+
+#ccall CFStringCreateWithPascalStringNoCopy, <CFAllocatorRef> -> <ConstStr255Param> -> <CFStringEncoding> -> <CFAllocatorRef> -> IO <CFStringRef>
+#ccall CFStringCreateWithCStringNoCopy     , <CFAllocatorRef> -> Ptr CChar -> <CFStringEncoding> -> <CFAllocatorRef> -> IO <CFStringRef>
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+#  ccall CFStringCreateWithBytesNoCopy, <CFAllocatorRef> -> Ptr <UInt8> -> <CFIndex> -> <CFStringEncoding> -> <Boolean> -> <CFAllocatorRef> -> IO <CFStringRef>
+#endif
+
+#cinline CFStringCreateWithSubstring, <CFAllocatorRef> -> <CFStringRef> -> Ptr <CFRange> -> IO <CFStringRef>
+#ccall   CFStringCreateCopy         , <CFAllocatorRef> -> <CFStringRef> -> IO <CFStringRef>
+-- NOTE: CFStringCreateWithFormat takes varargs.
+-- NOTE: CFStringCreateWithFormatAndArguments takes va_list.
+#ccall   CFStringCreateMutable      , <CFAllocatorRef> -> <CFIndex> -> IO <CFMutableStringRef>
+#ccall   CFStringCreateMutableCopy  , <CFAllocatorRef> -> <CFIndex> -> <CFStringRef> -> IO <CFMutableStringRef>
+#ccall   CFStringCreateMutableWithExternalCharactersNoCopy, <CFAllocatorRef> -> Ptr <UniChar> -> <CFIndex> -> <CFIndex> -> <CFAllocatorRef> -> IO <CFMutableStringRef>
+#ccall   CFStringGetLength          , <CFStringRef> -> IO <CFIndex>
+#ccall   CFStringGetCharacterAtIndex, <CFStringRef> -> <CFIndex> -> IO <UniChar>
+#cinline CFStringGetCharacters      , <CFStringRef> -> Ptr <CFRange> -> Ptr <UniChar> -> IO ()
+#ccall   CFStringGetPascalString    , <CFStringRef> -> <StringPtr> -> <CFIndex> -> <CFStringEncoding> -> IO <Boolean>
+#ccall   CFStringGetCString         , <CFStringRef> -> Ptr CChar -> <CFIndex> -> <CFStringEncoding> -> IO <Boolean>
+#ccall   CFStringGetPascalStringPtr , <CFStringRef> -> <CFStringEncoding> -> IO <ConstStringPtr>
+#ccall   CFStringGetCStringPtr      , <CFStringRef> -> <CFStringEncoding> -> IO (Ptr CChar)
+#ccall   CFStringGetCharactersPtr   , <CFStringRef> -> IO (Ptr <UniChar>)
+#cinline CFStringGetBytes           , <CFStringRef> -> Ptr <CFRange> -> <CFStringEncoding> -> <UInt8> -> <Boolean> -> Ptr <UInt8> -> <CFIndex> -> Ptr <CFIndex> -> IO <CFIndex>
+#ccall   CFStringCreateFromExternalRepresentation, <CFAllocatorRef> -> <CFDataRef> -> <CFStringEncoding> -> IO <CFStringRef>
+#ccall   CFStringCreateExternalRepresentation    , <CFAllocatorRef> -> <CFStringRef> -> <CFStringEncoding> -> <UInt8> -> IO <CFDataRef>
+#ccall   CFStringGetSmallestEncoding             , <CFStringRef> -> IO <CFStringEncoding>
+#ccall   CFStringGetFastestEncoding              , <CFStringRef> -> IO <CFStringEncoding>
+#ccall   CFStringGetSystemEncoding               , IO <CFStringEncoding>
+#ccall   CFStringGetMaximumSizeForEncoding       , <CFIndex> -> <CFStringEncoding> -> IO <CFIndex>
+#ccall   CFStringGetFileSystemRepresentation     , <CFStringRef> -> Ptr CChar -> <CFIndex> -> IO <Boolean>
+#ccall   CFStringGetMaximumSizeOfFileSystemRepresentation, <CFStringRef> -> IO <CFIndex>
+#ccall   CFStringCreateWithFileSystemRepresentation      , <CFAllocatorRef> -> Ptr CChar -> IO <CFStringRef>
+
+#num kCFCompareCaseInsensitive
+#num kCFCompareBackwards
+#num kCFCompareAnchored
+#num kCFCompareNonliteral
+#num kCFCompareLocalized
+#num kCFCompareNumerically
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+#  num kCFCompareDiacriticInsensitive
+#  num kCFCompareWidthInsensitive
+#  num kCFCompareForcedOrdering
+#endif
+#synonym_t CFStringCompareFlags, <CFOptionFlags>
+
+#if !defined(__WIN32__)
+#  if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+#    cinline CFStringCompareWithOptionsAndLocale, <CFStringRef> -> <CFStringRef> -> Ptr <CFRange> -> <CFOptionFlags> -> <CFLocaleRef> -> IO <CFComparisonResult>
+#  endif
+#endif
+
+#cinline CFStringCompareWithOptions, <CFStringRef> -> <CFStringRef> -> Ptr <CFRange> -> <CFOptionFlags> -> IO <CFComparisonResult>
+#ccall   CFStringCompare           , <CFStringRef> -> <CFStringRef> -> <CFOptionFlags> -> IO <CFComparisonResult>
+
+#if !defined(__WIN32__)
+#  if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+#    cinline CFStringFindWithOptionsAndLocale, <CFStringRef> -> <CFStringRef> -> Ptr <CFRange> -> <CFOptionFlags> -> <CFLocaleRef> -> Ptr <CFRange> -> IO <Boolean>
+#  endif
+#endif
+
+#cinline CFStringFindWithOptions           , <CFStringRef> -> <CFStringRef> -> Ptr <CFRange> -> <CFOptionFlags> -> Ptr <CFRange> -> IO <Boolean>
+#cinline CFStringCreateArrayWithFindResults, <CFAllocatorRef> -> <CFStringRef> -> <CFStringRef> -> Ptr <CFRange> -> <CFOptionFlags> -> IO <CFArrayRef>
+#cinline CFStringFind     , <CFStringRef> -> <CFStringRef> -> <CFOptionFlags> -> Ptr <CFRange> -> IO ()
+#ccall   CFStringHasPrefix, <CFStringRef> -> <CFStringRef> -> IO <Boolean>
+#ccall   CFStringHasSuffix, <CFStringRef> -> <CFStringRef> -> IO <Boolean>
+
+#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
+#  cinline CFStringGetRangeOfComposedCharactersAtIndex, <CFStringRef> -> <CFIndex> -> Ptr <CFRange> -> IO ()
+#  cinline CFStringFindCharacterFromSet               , <CFStringRef> -> <CFCharacterSetRef> -> Ptr <CFRange> -> <CFOptionFlags> -> Ptr <CFRange> -> IO <Boolean>
+#endif
+
+#cinline CFStringGetLineBounds     , <CFStringRef> -> Ptr <CFRange> -> Ptr <CFIndex> -> Ptr <CFIndex> -> Ptr <CFIndex> -> IO ()
+#cinline CFStringGetParagraphBounds, <CFStringRef> -> Ptr <CFRange> -> Ptr <CFIndex> -> Ptr <CFIndex> -> Ptr <CFIndex> -> IO ()
+#ccall   CFStringCreateByCombiningStrings      , <CFAllocatorRef> -> <CFArrayRef> -> <CFStringRef> -> IO <CFStringRef>
+#ccall   CFStringCreateArrayBySeparatingStrings, <CFAllocatorRef> -> <CFStringRef> -> <CFStringRef> -> IO <CFArrayRef>
+#ccall   CFStringGetIntValue       , <CFStringRef> -> IO <SInt32>
+#ccall   CFStringGetDoubleValue    , <CFStringRef> -> IO CDouble
+#ccall   CFStringAppend            , <CFMutableStringRef> -> <CFStringRef> -> IO ()
+#ccall   CFStringAppendCharacters  , <CFMutableStringRef> -> Ptr <UniChar> -> <CFIndex> -> IO ()
+#ccall   CFStringAppendPascalString, <CFMutableStringRef> -> <ConstStr255Param> -> <CFStringEncoding> -> IO ()
+#ccall   CFStringAppendCString     , <CFMutableStringRef> -> Ptr CChar -> <CFStringEncoding> -> IO ()
+-- NOTE: CFStringAppendFormat takes varargs.
+-- NOTE: CFStringAppendFormatAndArguments takes va_list.
+#ccall   CFStringInsert            , <CFMutableStringRef> -> <CFIndex> -> <CFStringRef> -> IO ()
+#cinline CFStringDelete            , <CFMutableStringRef> -> Ptr <CFRange> -> IO ()
+#cinline CFStringReplace           , <CFMutableStringRef> -> Ptr <CFRange> -> <CFStringRef> -> IO ()
+#ccall   CFStringReplaceAll        , <CFMutableStringRef> -> <CFStringRef> -> IO ()
+
+#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
+#  cinline CFStringFindAndReplace  , <CFMutableStringRef> -> <CFStringRef> -> <CFStringRef> -> Ptr <CFRange> -> <CFOptionFlags> -> IO <CFIndex>
+#endif
+
+#ccall CFStringSetExternalCharactersNoCopy, <CFMutableStringRef> -> Ptr <UniChar> -> <CFIndex> -> <CFIndex> -> IO ()
+#ccall CFStringPad           , <CFMutableStringRef> -> <CFStringRef> -> <CFIndex> -> <CFIndex> -> IO ()
+#ccall CFStringTrim          , <CFMutableStringRef> -> <CFStringRef> -> IO ()
+#ccall CFStringTrimWhitespace, <CFMutableStringRef> -> IO ()
+
+#ccall CFStringLowercase , <CFMutableStringRef> -> <CFLocaleRef> -> IO ()
+#ccall CFStringUppercase , <CFMutableStringRef> -> <CFLocaleRef> -> IO ()
+#ccall CFStringCapitalize, <CFMutableStringRef> -> <CFLocaleRef> -> IO ()
+
+#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
+#  num       kCFStringNormalizationFormD
+#  num       kCFStringNormalizationFormKD
+#  num       kCFStringNormalizationFormC
+#  num       kCFStringNormalizationFormKC
+#  synonym_t CFStringNormalizationForm   , <CFIndex>
+#  ccall     CFStringNormalize           , <CFMutableStringRef> -> <CFStringNormalizationForm> -> IO ()
+#endif
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+#  ccall CFStringFold, <CFMutableStringRef> -> <CFOptionFlags> -> <CFLocaleRef> -> IO ()
+#endif
+
+#ccall CFStringTransform, <CFMutableStringRef> -> Ptr <CFRange> -> <CFStringRef> -> <Boolean> -> IO <Boolean>
+
index 8c4b6e457f1fc87caef51fe63f0bd13a66cc7911..d2573d84c176384cb5ce5efcaf576dfd67479eaa 100644 (file)
@@ -35,6 +35,7 @@ Library
         Bindings.CoreFoundation.CFData
         Bindings.CoreFoundation.CFDictionary
         Bindings.CoreFoundation.CFLocale
+        Bindings.CoreFoundation.CFString
 
     C-Sources:
         cbits/helper_CFArray.c
@@ -43,6 +44,7 @@ Library
         cbits/helper_CFData.c
         cbits/helper_CFDictionary.c
         cbits/helper_CFLocale.c
+        cbits/helper_CFString.c
 
     Extensions:
         ForeignFunctionInterface
diff --git a/cbits/helper_CFString.c b/cbits/helper_CFString.c
new file mode 100644 (file)
index 0000000..b6288ef
--- /dev/null
@@ -0,0 +1,168 @@
+#include <bindings.cmacros.h>
+#include <CoreFoundation/CFString.h>
+
+CFStringRef
+inline_CFStringCreateWithSubstring(CFAllocatorRef alloc,
+                                   CFStringRef str,
+                                   CFRange* range) {
+    return CFStringCreateWithSubstring(alloc, str, *range);
+}
+
+void
+inline_CFStringGetCharacters(CFStringRef theString,
+                             CFRange* range,
+                             UniChar *buffer) {
+    return CFStringGetCharacters(theString, *range, buffer);
+}
+
+CFIndex
+inline_CFStringGetBytes(CFStringRef theString,
+                        CFRange* range,
+                        CFStringEncoding encoding,
+                        UInt8 lossByte,
+                        Boolean isExternalRepresentation,
+                        UInt8 *buffer,
+                        CFIndex maxBufLen,
+                        CFIndex *usedBufLen) {
+    return CFStringGetBytes(theString, *range, encoding,
+                            lossByte, isExternalRepresentation,
+                            buffer, maxBufLen, usedBufLen);
+}
+
+#if !defined(__WIN32__)
+#  if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+CFComparisonResult
+inline_CFStringCompareWithOptionsAndLocale(CFStringRef theString1,
+                                           CFStringRef theString2,
+                                           CFRange* rangeToCompare,
+                                           CFOptionFlags compareOptions,
+                                           CFLocaleRef locale) {
+    return CFStringCompareWithOptionsAndLocale(theString1, theString2,
+                                               *rangeToCompare,
+                                               compareOptions, locale);
+}
+#  endif
+#endif
+
+CFComparisonResult
+inline_CFStringCompareWithOptions(CFStringRef theString1,
+                                  CFStringRef theString2,
+                                  CFRange* rangeToCompare,
+                                  CFOptionFlags compareOptions) {
+    return CFStringCompareWithOptions(theString1, theString2,
+                                      *rangeToCompare, compareOptions);
+}
+
+#if !defined(__WIN32__)
+#  if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+Boolean
+inline_CFStringFindWithOptionsAndLocale(CFStringRef theString,
+                                        CFStringRef stringToFind,
+                                        CFRange* rangeToSearch,
+                                        CFOptionFlags searchOptions,
+                                        CFLocaleRef locale,
+                                        CFRange *result) {
+    return CFStringFindWithOptionsAndLocale(theString, stringToFind,
+                                            *rangeToSearch,
+                                            searchOptions, locale, result);
+}
+#  endif
+#endif
+
+Boolean
+inline_CFStringFindWithOptions(CFStringRef theString,
+                               CFStringRef stringToFind,
+                               CFRange* rangeToSearch,
+                               CFOptionFlags searchOptions,
+                               CFRange *result) {
+    return CFStringFindWithOptions(theString, stringToFind,
+                                   *rangeToSearch,
+                                   searchOptions, result);
+}
+
+CFArrayRef
+inline_CFStringCreateArrayWithFindResults(CFAllocatorRef alloc,
+                                          CFStringRef theString,
+                                          CFStringRef stringToFind,
+                                          CFRange* rangeToSearch,
+                                          CFOptionFlags compareOptions) {
+    return CFStringCreateArrayWithFindResults(alloc, theString, stringToFind,
+                                              *rangeToSearch, compareOptions);
+}
+
+void
+inline_CFStringFind(CFStringRef theString,
+                    CFStringRef stringToFind,
+                    CFOptionFlags compareOptions,
+                    CFRange* result) {
+    *result = CFStringFind(theString, stringToFind, compareOptions);
+}
+
+#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
+void
+inline_CFStringGetRangeOfComposedCharactersAtIndex(CFStringRef theString,
+                                                   CFIndex theIndex,
+                                                   CFRange* result) {
+    *result = CFStringGetRangeOfComposedCharactersAtIndex(theString, theIndex);
+}
+
+Boolean
+inline_CFStringFindCharacterFromSet(CFStringRef theString,
+                                    CFCharacterSetRef theSet,
+                                    CFRange* rangeToSearch,
+                                    CFOptionFlags searchOptions,
+                                    CFRange *result) {
+    return CFStringFindCharacterFromSet(theString, theSet,
+                                        *rangeToSearch,
+                                        searchOptions, result);
+}
+#endif
+
+void
+inline_CFStringGetLineBounds(CFStringRef theString,
+                             CFRange* range,
+                             CFIndex *lineBeginIndex,
+                             CFIndex *lineEndIndex,
+                             CFIndex *contentsEndIndex) {
+    return CFStringGetLineBounds(theString, *range,
+                                 lineBeginIndex, lineEndIndex,
+                                 contentsEndIndex);
+}
+
+void
+inline_CFStringGetParagraphBounds(CFStringRef string,
+                                  CFRange* range,
+                                  CFIndex *parBeginIndex,
+                                  CFIndex *parEndIndex,
+                                  CFIndex *contentsEndIndex) {
+    return CFStringGetParagraphBounds(string, *range,
+                                      parBeginIndex, parEndIndex,
+                                      contentsEndIndex);
+}
+
+void
+inline_CFStringDelete(CFMutableStringRef theString,
+                      CFRange* range) {
+    return CFStringDelete(theString, *range);
+}
+
+void
+inline_CFStringReplace(CFMutableStringRef theString,
+                       CFRange* range,
+                       CFStringRef replacement) {
+    return CFStringReplace(theString, *range, replacement);
+}
+
+#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
+CFIndex
+inline_CFStringFindAndReplace(CFMutableStringRef theString,
+                              CFStringRef stringToFind,
+                              CFStringRef replacementString,
+                              CFRange* rangeToSearch,
+                              CFOptionFlags compareOptions) {
+    return CFStringFindAndReplace(theString, stringToFind,
+                                  replacementString, *rangeToSearch,
+                                  compareOptions);
+}
+#endif
+