public static int[] getSearchTermOccurrences(
            String searchTerm,
            String content)
    {
        List<StyleRange> styleRange;
        List<Integer> ranges;
        Display disp = Display.getCurrent();
        StyleRange myStyleRange =
            new StyleRange(0, 0, null, disp.getSystemColor(SWT.COLOR_YELLOW));

        // reset the StyleRange-Array for each new field
        styleRange = new ArrayList<StyleRange>();
        ranges = new ArrayList<Integer>(); // reset the ranges-array
        if (searchTerm.equals("")) {
            return new int[] {};
        }

        // determine all occurrences of the searchText and write the beginning
        // and length of each occurrence into an array
        for (int i = 0; i < content.length(); i++) {
            if (i + searchTerm.length() <= content.length()
                    && content.substring(i, i + searchTerm.length())
                            .equalsIgnoreCase(searchTerm)) {
                // ranges format: n->start of the range, n+1->length of the
                // range
                ranges.add(i);
                ranges.add(searchTerm.length());
            }
        }
        // convert the list into an int[] and make sure that overlapping
        // search term occurrences are are merged
        int[] intRanges = new int[ranges.size()];
        int arrayIndexCounter = 0;
        for (int listIndexCounter = 0; listIndexCounter < ranges.size(); listIndexCounter++) {
            if (listIndexCounter % 2 == 0) {
                if (searchTerm.length() > 1
                        && listIndexCounter != 0
                        && ranges.get(listIndexCounter - 2)
                                + ranges.get(listIndexCounter - 1) >= ranges
                                .get(listIndexCounter)) {
                    intRanges[arrayIndexCounter - 1] = 0
                            - ranges.get(listIndexCounter - 2)
                            + ranges.get(listIndexCounter)
                            + ranges.get(++listIndexCounter);
                } else {
                    intRanges[arrayIndexCounter++] = ranges
                            .get(listIndexCounter);
                }
            } else {
                intRanges[arrayIndexCounter++] = ranges.get(listIndexCounter);
                styleRange.add(myStyleRange);
            }
        }
        // if there have been any overlappings we need to reduce the size of
        // the array to avoid conflicts in the setStyleRanges method
        int[] intRangesCorrectSize = new int[arrayIndexCounter];
        System.arraycopy(intRanges, 0, intRangesCorrectSize, 0,
                arrayIndexCounter);

        return intRangesCorrectSize;
    }