TelephoneNumberDetectorCocoa.cpp [plain text]
#include "config.h"
#include "TelephoneNumberDetector.h"
#if ENABLE(TELEPHONE_NUMBER_DETECTION)
#include "SoftLinking.h"
#if __has_include(<DataDetectorsCore/DDDFAScanner.h>)
#include <DataDetectorsCore/DDDFAScanner.h>
#else
typedef struct __DDDFAScanner DDDFAScanner, * DDDFAScannerRef;
struct __DDDFACache;
#endif
SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(DataDetectorsCore)
SOFT_LINK(DataDetectorsCore, DDDFACacheCreateFromFramework, struct __DDDFACache*, (), ())
SOFT_LINK(DataDetectorsCore, DDDFAScannerCreateFromCache, DDDFAScannerRef, (struct __DDDFACache* cache), (cache))
SOFT_LINK(DataDetectorsCore, DDDFAScannerFirstResultInUnicharArray, Boolean, (DDDFAScannerRef scanner, const UniChar* str, unsigned length, int* startPos, int* endPos), (scanner, str, length, startPos, endPos))
namespace WebCore {
namespace TelephoneNumberDetector {
static DDDFAScannerRef phoneNumbersScanner()
{
if (!DataDetectorsCoreLibrary())
return nullptr;
static struct __DDDFACache* cache = DDDFACacheCreateFromFramework();
if (!cache)
return nullptr;
static DDDFAScannerRef scanner = DDDFAScannerCreateFromCache(cache);
return scanner;
}
bool isSupported()
{
return phoneNumbersScanner() != nullptr;
}
bool find(const UChar* buffer, unsigned length, int* startPos, int* endPos)
{
ASSERT(isSupported());
return DDDFAScannerFirstResultInUnicharArray(phoneNumbersScanner(), buffer, length, startPos, endPos);
}
} }
#endif // ENABLE(TELEPHONE_NUMBER_DETECTION)