|
1 /* |
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 package propertiesparser.parser; |
|
24 |
|
25 import java.util.regex.Pattern; |
|
26 |
|
27 /** |
|
28 * A line of text within the message file. |
|
29 * The lines form a doubly linked list for simple navigation. |
|
30 */ |
|
31 public class MessageLine { |
|
32 |
|
33 static final Pattern emptyOrCommentPattern = Pattern.compile("( *#.*)?"); |
|
34 static final Pattern typePattern = Pattern.compile("[-\\\\'A-Z\\.a-z ]+( \\([A-Za-z 0-9]+\\))?"); |
|
35 static final Pattern infoPattern = Pattern.compile(String.format("# ([0-9]+: %s, )*[0-9]+: %s", |
|
36 typePattern.pattern(), typePattern.pattern())); |
|
37 |
|
38 public String text; |
|
39 MessageLine prev; |
|
40 MessageLine next; |
|
41 |
|
42 MessageLine(String text) { |
|
43 this.text = text; |
|
44 } |
|
45 |
|
46 public boolean isEmptyOrComment() { |
|
47 return emptyOrCommentPattern.matcher(text).matches(); |
|
48 } |
|
49 |
|
50 public boolean isInfo() { |
|
51 return infoPattern.matcher(text).matches(); |
|
52 } |
|
53 |
|
54 boolean hasContinuation() { |
|
55 return (next != null) && text.endsWith("\\"); |
|
56 } |
|
57 |
|
58 MessageLine append(String text) { |
|
59 MessageLine l = new MessageLine(text); |
|
60 append(l); |
|
61 return l; |
|
62 } |
|
63 |
|
64 void append(MessageLine l) { |
|
65 assert l.prev == null && l.next == null; |
|
66 l.prev = this; |
|
67 l.next = next; |
|
68 if (next != null) { |
|
69 next.prev = l; |
|
70 } |
|
71 next = l; |
|
72 } |
|
73 } |