~ubuntu-branches/ubuntu/natty/mozvoikko/natty-proposed

« back to all changes in this revision

Viewing changes to src/mozVoikkoSpell.cpp

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2011-12-20 00:19:52 UTC
  • mfrom: (18.1.3 natty-security)
  • Revision ID: package-import@ubuntu.com-20111220001952-kgbjh71gwu6l8023
Tags: 1.10.0-0ubuntu0.11.04.4
* Update for Firefox 9 (LP: #906389)
  - update debian/patches/port_to_latest_firefox.patch for
    mozISpellCheckingEngine changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
    delete voikkoSpell;
84
84
}
85
85
 
 
86
NS_IMETHODIMP mozVoikkoSpell::AddDirectory(nsIFile *aDir)
 
87
{
 
88
    return NS_ERROR_NOT_IMPLEMENTED;
 
89
}
 
90
 
 
91
NS_IMETHODIMP mozVoikkoSpell::RemoveDirectory(nsIFile *aDir)
 
92
{
 
93
    return NS_ERROR_NOT_IMPLEMENTED;
 
94
}
 
95
 
 
96
NS_IMETHODIMP mozVoikkoSpell::LoadDictionariesFromDir(nsIFile* aFile)
 
97
{
 
98
        return NS_ERROR_NOT_IMPLEMENTED;
 
99
}
 
100
 
86
101
/* attribute wstring dictionary; */
87
102
NS_IMETHODIMP mozVoikkoSpell::GetDictionary(PRUnichar **aDictionary)
88
103
{
119
134
        if (!voikkoSpell)
120
135
            return NS_ERROR_FAILURE;
121
136
 
122
 
        nsCOMPtr<nsICharsetConverterManager> ccm = do_GetService(kCharsetConverterManagerCID, &rv);
123
 
        NS_ENSURE_SUCCESS(rv, rv);
124
 
 
125
 
        rv = ccm->GetUnicodeDecoder(voikkoSpell->get_dic_encoding(), getter_AddRefs(mDecoder));
126
 
        NS_ENSURE_SUCCESS(rv, rv);
127
 
        rv = ccm->GetUnicodeEncoder(voikkoSpell->get_dic_encoding(), getter_AddRefs(mEncoder));
128
 
        if (mEncoder && NS_SUCCEEDED(rv))
129
 
        {
130
 
            mEncoder->SetOutputErrorBehavior(mEncoder->kOnError_Signal, nsnull, '?');
131
 
        }
132
 
 
133
 
        NS_ENSURE_SUCCESS(rv, rv);
134
137
        mLanguage.Assign(newDict);
135
138
 
136
139
        return rv;
227
230
nsresult mozVoikkoSpell::ConvertCharset(const PRUnichar* aStr, char ** aDst)
228
231
{
229
232
    NS_ENSURE_ARG_POINTER(aDst);
230
 
    NS_ENSURE_TRUE(mEncoder, NS_ERROR_NULL_POINTER);
231
 
 
232
 
    PRInt32 outLength;
233
 
    PRInt32 inLength = NS_strlen(aStr);
234
 
    nsresult rv = mEncoder->GetMaxLength(aStr, inLength, &outLength);
235
 
    NS_ENSURE_SUCCESS(rv, rv);
236
 
 
237
 
    *aDst = (char *) NS_Alloc(sizeof(char) * (outLength+1));
238
 
    NS_ENSURE_TRUE(*aDst, NS_ERROR_OUT_OF_MEMORY);
239
 
 
240
 
    rv = mEncoder->Convert(aStr, &inLength, *aDst, &outLength);
241
 
    if (NS_SUCCEEDED(rv))
242
 
        (*aDst)[outLength] = '\0'; 
243
 
 
244
 
    return rv;
 
233
 
 
234
    nsString str_u16(aStr);
 
235
    nsCString str_u8 = NS_ConvertUTF16toUTF8(str_u16);
 
236
    const char *str = str_u8.get();
 
237
    *aDst = (char*)NS_Alloc(1 + strlen(str));
 
238
    strcpy(*aDst, str);
 
239
 
 
240
    return NS_OK;
245
241
}
246
242
 
247
243
/* boolean Check (in wstring word); */
294
290
            for (index = 0; index < *aSuggestionCount && NS_SUCCEEDED(rv); ++index)
295
291
            {
296
292
                // Convert the suggestion to utf16
297
 
                PRInt32 inLength = strlen(wlst[index]);
298
 
                PRInt32 outLength;
299
 
                rv = mDecoder->GetMaxLength(wlst[index], inLength, &outLength);
300
 
                if (NS_SUCCEEDED(rv))
301
 
                {
302
 
                    (*aSuggestions)[index] = (PRUnichar *) NS_Alloc(sizeof(PRUnichar) * (outLength+1));
303
 
                    if ((*aSuggestions)[index])
304
 
                    {
305
 
                        rv = mDecoder->Convert(wlst[index], &inLength, (*aSuggestions)[index], &outLength);
306
 
                        if (NS_SUCCEEDED(rv))
307
 
                            (*aSuggestions)[index][outLength] = 0;
308
 
                    } 
309
 
                    else
310
 
                        rv = NS_ERROR_OUT_OF_MEMORY;
311
 
                }
 
293
                nsString str_u16 = NS_ConvertUTF8toUTF16(wlst[index]);
 
294
                PRUint32 len = str_u16.Length();
 
295
                PRUnichar *tmp = (PRUnichar *)NS_Alloc(sizeof(PRUnichar) * (1 + len));
 
296
                memcpy(tmp, str_u16.get(), sizeof(PRUnichar) * (1 + len));
 
297
                (*aSuggestions)[index] = tmp;
312
298
            }
313
299
 
314
300
            if (NS_FAILED(rv))
322
308
 
323
309
    return rv;
324
310
}
325
 
 
326
 
/* void loadDictionariesFromDir (in nsIFile dir); */
327
 
NS_IMETHODIMP mozVoikkoSpell::LoadDictionariesFromDir(nsIFile *dir)
328
 
{
329
 
    return NS_ERROR_NOT_IMPLEMENTED;
330
 
}