~ubuntu-branches/ubuntu/quantal/kiten/quantal-proposed

« back to all changes in this revision

Viewing changes to lib/entry.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-16 13:14:44 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111216131444-fxt8pt2pha54qmdu
Tags: 4:4.7.90-0ubuntu1
New upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * Copyright (C) 2001 Jason Katz-Brown <jason@katzbrown.com>                 *
4
4
 * Copyright (C) 2006 Joseph Kerian <jkerian@gmail.com>                      *
5
5
 * Copyright (C) 2006 Eric Kjeldergaard <kjelderg@gmail.com>                 *
 
6
 * Copyright (C) 2011 Daniel E. Moctezuma <democtezuma@gmail.com>            *
6
7
 *                                                                           *
7
8
 * This library is free software; you can redistribute it and/or             *
8
9
 * modify it under the terms of the GNU Library General Public               *
156
157
 */
157
158
inline QString Entry::HTMLMeanings() const
158
159
{
159
 
  return "<span class=\"Meanings\">" + Meanings.join(outputListDelimiter)
160
 
          + "</span>";
 
160
  return QString( "<span class=\"Meanings\">%1</span>" )
 
161
             .arg( Meanings.join( outputListDelimiter ) );
161
162
}
162
163
 
163
164
/* Prepares Readings for output as HTML */
169
170
    list += makeLink( it );
170
171
  }
171
172
 
172
 
  return "<span class=\"Readings\">" + list.join( outputListDelimiter ) + "</span>";
 
173
  return QString( "<span class=\"Readings\">%1</span>" )
 
174
             .arg( list.join( outputListDelimiter ) );
173
175
}
174
176
 
175
177
/**
177
179
 */
178
180
inline QString Entry::HTMLWord() const
179
181
{
180
 
  return "<span class=\"Word\">" + Word + "</span>";
 
182
  return QString( "<span class=\"Word\">%1</span>" ).arg( Word );
181
183
}
182
184
 
183
185
void Entry::init()
208
210
 */
209
211
bool Entry::listMatch( const QStringList &list, const QStringList &test, DictQuery::MatchType type ) const
210
212
{
211
 
  if( type == DictQuery::matchExact )
 
213
  if( type == DictQuery::Exact )
212
214
  {
213
215
    foreach( const QString &it, test )
214
216
    {
218
220
      }
219
221
    }
220
222
  }
221
 
  else if( type == DictQuery::matchBeginning )
 
223
  else if( type == DictQuery::Beginning )
222
224
  {
223
225
    foreach( const QString &it, test )
224
226
    {
237
239
      }
238
240
    }
239
241
  }
 
242
  else if( type == DictQuery::Ending )
 
243
  {
 
244
    foreach( const QString &it, test )
 
245
    {
 
246
      bool found = false;
 
247
      foreach( const QString &it2, list )
 
248
      {
 
249
        if( it2.endsWith( it ) )
 
250
        {
 
251
          found = true;
 
252
          break;
 
253
        }
 
254
      }
 
255
      if( ! found )
 
256
      {
 
257
        return false;
 
258
      }
 
259
    }
 
260
  }
240
261
  else
241
262
  {
242
263
    foreach( const QString &it, test )
267
288
 */
268
289
inline QString Entry::makeLink( const QString &entryString ) const
269
290
{
270
 
  return "<a href=\"" + entryString + "\">" + entryString + "</a>";
 
291
  return QString( "<a href=\"%1\">%1</a>" ).arg( entryString );
271
292
}
272
293
 
273
294
bool Entry::matchesQuery( const DictQuery &query ) const
274
295
{
275
296
  if( ! query.getWord().isEmpty() )
276
297
  {
277
 
    if( query.getMatchType() == DictQuery::matchExact
 
298
    if( query.getMatchType() == DictQuery::Exact
278
299
      && this->getWord() != query.getWord() )
279
300
    {
280
301
      return false;
281
302
    }
282
 
    if( query.getMatchType() == DictQuery::matchBeginning
283
 
      && ! this->getWord().startsWith(query.getWord() ) )
284
 
    {
285
 
      return false;
286
 
    }
287
 
    if( query.getMatchType() == DictQuery::matchAnywhere
288
 
      && ! this->getWord().contains(query.getWord() ) )
 
303
    if( query.getMatchType() == DictQuery::Beginning
 
304
      && ! this->getWord().startsWith( query.getWord() ) )
 
305
    {
 
306
      return false;
 
307
    }
 
308
    if( query.getMatchType() == DictQuery::Ending
 
309
      && ! this->getWord().endsWith( query.getWord() ) )
 
310
    {
 
311
      return false;
 
312
    }
 
313
    if( query.getMatchType() == DictQuery::Anywhere
 
314
      && ! this->getWord().contains( query.getWord() ) )
289
315
    {
290
316
      return false;
291
317
    }
304
330
  {
305
331
    switch ( query.getMatchType() )
306
332
    {
307
 
      case DictQuery::matchExact:
 
333
      case DictQuery::Exact:
308
334
        if ( getWord() != query.getPronunciation() )
309
335
        {
310
336
          return false;
311
337
        }
312
338
        break;
313
 
      case DictQuery::matchBeginning:
 
339
      case DictQuery::Beginning:
314
340
        if ( ! getWord().startsWith( query.getPronunciation() ) )
315
341
        {
316
342
          return false;
317
343
        }
318
344
        break;
319
 
      case DictQuery::matchAnywhere:
 
345
      case DictQuery::Ending:
 
346
        if ( ! getWord().endsWith( query.getPronunciation() ) )
 
347
        {
 
348
          return false;
 
349
        }
 
350
      case DictQuery::Anywhere:
320
351
        if ( ! getWord().contains( query.getPronunciation() ) )
321
352
        {
322
353
          return false;
352
383
 */
353
384
QString Entry::toHTML() const
354
385
{
355
 
  return "<div class=\"Entry\">" + HTMLWord() + HTMLReadings() + HTMLMeanings() + "</div>";
 
386
  return QString( "<div class=\"Entry\">%1%2%3</div>" )
 
387
             .arg( HTMLWord() )
 
388
             .arg( HTMLReadings() )
 
389
             .arg( HTMLMeanings() );
356
390
}
357
391
 
358
392
inline QString Entry::toKVTML() const
364
398
   </e>
365
399
   */
366
400
  //TODO: en should not necessarily be the language here.
367
 
  return "<e>\n<o l=\"en\">" + getMeanings() + "</o>\n"
368
 
         "<t l=\"jp-kanji\">" + getWord() + "</t>\n"
369
 
       + "<t l=\"jp-kana\">" + getReadings() + "</t></e>\n\n";
 
401
  return QString( "<e>\n<o l=\"en\">%1</o>\n"
 
402
                  "<t l=\"jp-kanji\">%2</t>\n"
 
403
                  "<t l=\"jp-kana\">%3</t></e>\n\n" ).arg( getMeanings() )
 
404
                                                     .arg( getWord() )
 
405
                                                     .arg( getReadings() );
370
406
}
371
407
 
372
408
/**
376
412
 */
377
413
QString Entry::toString() const
378
414
{
379
 
  return Word + " (" + getReadings() + ") " + getMeanings();
 
415
  return QString( "%1 (%2) %3" ).arg( Word )
 
416
                                .arg( getReadings() )
 
417
                                .arg( getMeanings() );
380
418
}
381
419
 
382
420
/**
410
448
      }
411
449
      else if( field == QString( "Meaning" ) )
412
450
      {
413
 
        return listMatch( that.getMeaningsList(), this->getMeaningsList(), DictQuery::matchExact )
 
451
        return listMatch( that.getMeaningsList(), this->getMeaningsList(), DictQuery::Exact )
414
452
               && ( that.getMeaningsList().count() != this->getMeaningsList().count() );
415
453
      }
416
454
      else if( field == QString( "Reading" ) )
417
455
      {
418
 
        return listMatch( that.getReadingsList(), this->getReadingsList(), DictQuery::matchExact )
 
456
        return listMatch( that.getReadingsList(), this->getReadingsList(), DictQuery::Exact )
419
457
               && ( that.getReadingsList().count() != this->getReadingsList().count() );
420
458
      }
421
459
      else