blob: c46d5db665c1d05664ba318284aa0d372fe8dfe2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/*******************************************************************************
* Copyright (c) 2009 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Alexander Kurtakov - initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.man.parser;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.text.Document;
/**
* IDocument for a given man page.
*/
// TODO consider bold and underline symbols to handle ranges.
public class ManDocument extends Document {
private List<Integer> boldSymbols = new ArrayList<Integer>();
private List<Integer> underlineSymbols = new ArrayList<Integer>();
/**
* Creates an IDocument for the given man page and taking care for marking
* bold and underline symbols.
*
* @param manPage
* The man page to create document for.
*/
public ManDocument(String manPage) {
StringBuilder sb = new ManParser().getRawManPage(manPage);
while (sb.indexOf("\b") != -1) {
int index = sb.indexOf("\b");
if (sb.charAt(index - 1) == '_') {
sb.replace(index - 1, index + 2, sb.substring(index + 1,
index + 2));
underlineSymbols.add(index - 1);
} else {
sb.replace(index - 1, index + 1, sb.substring(index - 1,
index - 1));
boldSymbols.add(index - 1);
}
}
set(sb.toString());
}
/**
* Returns the indexes of bold symbols.
*
* @return List of bold symbols.
*/
public List<Integer> getBoldSymbols() {
return boldSymbols;
}
/**
* Returns the indexes of underline symbols.
*
* @return List of underline symbols.
*/
public List<Integer> getUnderlinedSymbols() {
return underlineSymbols;
}
}
|