Skip to content

Commit

Permalink
introduce autorelease context and string converstion routines
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Mar 23, 2012
1 parent 8d108e0 commit 783ba18
Showing 1 changed file with 52 additions and 7 deletions.
59 changes: 52 additions & 7 deletions src/cpp/core/spelling/MacSpellChecker.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,45 @@

#include <core/spelling/SpellChecker.hpp>

#include <iostream>

#include <boost/utility.hpp>
#include <boost/scoped_ptr.hpp>

#include <core/Error.hpp>

#import <Foundation/NSString.h>
#import <Foundation/NSAutoreleasePool.h>
#import <AppKit/NSSpellChecker.h>

namespace core {
namespace spelling {

namespace {

class AutoreleaseContext : boost::noncopyable
{
public:
AutoreleaseContext()
{
pool_ = [[NSAutoreleasePool alloc] init];
}

~AutoreleaseContext()
{
try
{
[pool_ release];
}
catch(...)
{
}
}

private:
NSAutoreleasePool* pool_;
};

class MacSpellChecker : public SpellChecker
{
public:
Expand All @@ -44,59 +71,77 @@

Error initialize()
{
if([NSSpellChecker sharedSpellCheckerExists])
{
// do nothing...we are just executing this to make sure we
// are linking to AppKit correctly
}
AutoreleaseContext arContext;


return Success();
}

public:
Error checkSpelling(const std::string& word, bool *pCorrect)
{
AutoreleaseContext arContext;

return Success();
}

Error suggestionList(const std::string& word, std::vector<std::string>* pSug)
{
AutoreleaseContext arContext;

return Success();
}

Error analyzeWord(const std::string& word, std::vector<std::string>* pResult)
{
AutoreleaseContext arContext;

return Success();
}

Error stemWord(const std::string& word, std::vector<std::string>* pResult)
{
AutoreleaseContext arContext;

return Success();
}

Error addWord(const std::string& word, bool *pAdded)
{
AutoreleaseContext arContext;

return Success();
}

Error removeWord(const std::string& word, bool *pRemoved)
{
AutoreleaseContext arContext;

return Success();
}

Error addDictionary(const FilePath& dicPath,
const std::string& key,
bool *pAdded)
{
AutoreleaseContext arContext;

return Success();
}

private:


NSString* toNSString(const std::string& str)
{
const char* cStr = str.c_str();
NSString* nsStr = [[NSString alloc] initWithUTF8String: cStr];
return nsStr;
return [NSString stringWithUTF8String: cStr];
}

std::string toStdString(NSString* nsString)
{
const char* cStr = [nsString UTF8String];
return std::string(cStr);
}

};
Expand Down

0 comments on commit 783ba18

Please sign in to comment.