~ubuntu-branches/ubuntu/natty/jabref/natty

« back to all changes in this revision

Viewing changes to src/java/net/sf/jabref/groups/KeywordGroup.java

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2010-04-27 16:49:34 UTC
  • mfrom: (2.1.8 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100427164934-ozu2dvinslmo3444
Tags: 2.6+ds-2
debian/control: add "Recommends: xdg-utils"; thanks to Vincent Fourmond
for the bug report (closes: #579346). Change xpdf to xpdf-reader in
Suggests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
 
63
63
        protected void compilePattern() throws IllegalArgumentException,
64
64
                        PatternSyntaxException {
65
 
                m_pattern = m_caseSensitive ? Pattern.compile(m_searchExpression)
66
 
                                : Pattern.compile(m_searchExpression, Pattern.CASE_INSENSITIVE);
 
65
                m_pattern = m_caseSensitive ? Pattern.compile("\\b"+m_searchExpression+"\\b")
 
66
                                : Pattern.compile("\\b"+m_searchExpression+"\\b", Pattern.CASE_INSENSITIVE);
67
67
        }
68
68
 
69
69
        /**
239
239
                if (m_regExp)
240
240
                        return m_pattern.matcher(content).find();
241
241
                if (m_caseSensitive)
242
 
                        return content.indexOf(m_searchExpression) >= 0;
243
 
                content = content.toLowerCase();
244
 
                return content.indexOf(m_searchExpression.toLowerCase()) >= 0;
 
242
                        return containsWord(m_searchExpression, content);
 
243
                return containsWord(m_searchExpression.toLowerCase(), content.toLowerCase());
245
244
        }
246
245
 
 
246
    /**
 
247
     * Look for the given non-regexp string in another string, but check whether a
 
248
     * match concerns a complete word, not part of a word.
 
249
     * @param word The word to look for.
 
250
     * @param text The string to look in.
 
251
     * @return true if the word was found, false otherwise.
 
252
     */
 
253
    private static boolean containsWord(String word, String text) {
 
254
        int piv = 0;
 
255
        while (piv < text.length()) {
 
256
            int ind = text.indexOf(word, piv);
 
257
            if (ind < 0)
 
258
                return false;
 
259
            // Found a match. See if it is a complete word:
 
260
            if (((ind == 0) || !Character.isLetterOrDigit(text.charAt(ind-1))) &&
 
261
                ((ind+word.length() == text.length()) || !Character.isLetterOrDigit(text.charAt(ind+word.length())))) {
 
262
                return true;
 
263
            }
 
264
            else piv = ind+1;
 
265
        }
 
266
        return false;
 
267
    }
 
268
 
247
269
        /**
248
270
         * Removes matches of searchString in the entry's field. This is only
249
271
         * possible if the search expression is not a regExp.
354
376
            sb.append("<i>").append(Util.quoteForHTML(getName())).append("</i>");
355
377
                else
356
378
                        sb.append(Util.quoteForHTML(getName()));
357
 
        sb.append("</b> - dynamic group (<b>").append(m_searchField).
358
 
            append("</b> contains <b>").
 
379
        sb.append(Globals.lang("</b> - dynamic group (<b>")).append(m_searchField).
 
380
            append(Globals.lang("</b> contains <b>")).
359
381
            append(Util.quoteForHTML(m_searchExpression)).append("</b>)");
360
382
                switch (getHierarchicalContext()) {
361
383
                case AbstractGroup.INCLUDING:
362
 
                        sb.append(", includes subgroups");
 
384
                        sb.append(Globals.lang(", includes subgroups"));
363
385
                        break;
364
386
                case AbstractGroup.REFINING:
365
 
                        sb.append(", refines supergroup");
 
387
                        sb.append(Globals.lang(", refines supergroup"));
366
388
                        break;
367
389
                default:
368
390
                        break;