Revision 2391

tmp/org.txm.utils/src/org/txm/utils/AsciiUtils.java (revision 2391)
115 115
	 * @param s the s
116 116
	 * @return the string
117 117
	 */
118
	public static String buildAttributeId(String s) {
118
	public static String buildWordId(String s) {
119 119

  
120
		//TODO: replace this with a lib managing the ID attribute format 
121 120
		if (s.length() == 0) return s;
121
		
122
		// ensure the "w_" prefix presence
123
		if (s.startsWith("w")) {
124
			if (!s.startsWith("w_")) {
125
				s = "w_"+s.substring(1);
126
			}
127
		} else {
128
			s = "w_"+s;
129
		}
122 130

  
123 131
		String rez = convertNonAscii(s).toLowerCase();
124 132
		rez = rez.replaceAll("\\p{Space}++","_");
125 133
		rez = rez.replaceAll("[¤€§µ£°().,;:/?§%\"'*+\\-}\\]\\[{#~&]",""); //$NON-NLS-1$ //$NON-NLS-2$
126
		// remove first chars if number
127
		char c = rez.charAt(0);
128
		while (c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9') {
129
			rez = rez.substring(1);
130
			if (rez.length() == 0) return "";
131
			c = rez.charAt(0);
132
		}
133 134

  
134 135
		return rez;
135 136
	}
136

  
137
	
137 138
	/**
139
	 * Builds attribute id.
140
	 *
141
	 * @param s the s
142
	 * @return the string
143
	 */
144
	public static String buildAttributeId(String s) {
145
		return buildId(s);
146
	}
147
	
148
	/**
138 149
	 * Builds the id.
139 150
	 *
140 151
	 * @param s the s
......
142 153
	 */
143 154
	public static String buildId(String s)
144 155
	{
156
		//TODO: replace this with a lib managing the ID attribute format 
145 157
		if (s.length() == 0) return s;
146 158

  
147
		String rez = removePunct(convertNonAscii(s)).toLowerCase();
148
		//¤€§µ£°
149
		rez = rez.replaceAll("[¤€§µ£° ]",""); //$NON-NLS-1$ //$NON-NLS-2$
150

  
159
		String rez = convertNonAscii(s).toLowerCase();
160
		rez = rez.replaceAll("\\p{Space}++","_");
161
		rez = rez.replaceAll("_","-");
162
		rez = rez.replaceAll("[¤€§µ£°().,;:/?§%\"'*+\\}\\]\\[{#~&]",""); //$NON-NLS-1$ //$NON-NLS-2$
151 163
		// remove first chars if number
152 164
		char c = rez.charAt(0);
153 165
		while (c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9') {

Also available in: Unified diff