View | Details | Raw Unified | Return to bug 8518 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.properties (+4 lines)
Lines 29-34 Link Here
29
upperCase.label= To Upper Case
29
upperCase.label= To Upper Case
30
lowerCase.description= Changes the selection to lower case
30
lowerCase.description= Changes the selection to lower case
31
lowerCase.label= To Lower Case
31
lowerCase.label= To Lower Case
32
invertCase.description= Inverts the case of the selection
33
invertCase.label= Invert Case
34
capitalizeCase.description= Capitalizes the selection
35
capitalizeCase.label= Capitalize
32
36
33
markerAnnotationSpecification.label= Marker Annotation Specification
37
markerAnnotationSpecification.label= Marker Annotation Specification
34
38
(-)plugin.xml (-1 / +31 lines)
Lines 129-135 Link Here
129
            configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
129
            configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
130
      </keyBinding>
130
      </keyBinding>
131
   </extension>
131
   </extension>
132
   
132
   <extension
133
         point="org.eclipse.ui.commands">
134
      <command
135
            name="%invertCase.label"
136
            description="%invertCase.description"
137
            category="org.eclipse.ui.category.textEditor"
138
            id="org.eclipse.ui.edit.text.invertCase">
139
      </command>
140
      <keyBinding
141
            string="Ctrl+Shift+I"
142
            scope="org.eclipse.ui.textEditorScope"
143
            command="org.eclipse.ui.edit.text.invertCase"
144
            configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
145
      </keyBinding>
146
   </extension>   
147
   <extension
148
         point="org.eclipse.ui.commands">
149
      <command
150
            name="%capitalizeCase.label"
151
            description="%capitalizeCase.description"
152
            category="org.eclipse.ui.category.textEditor"
153
            id="org.eclipse.ui.edit.text.capitalizeCase">
154
      </command>
155
      <keyBinding
156
            string="Ctrl+Shift+C"
157
            scope="org.eclipse.ui.textEditorScope"
158
            command="org.eclipse.ui.edit.text.capitalizeCase"
159
            configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
160
      </keyBinding>
161
   </extension>  
162
      
133
<!-- action sets -->
163
<!-- action sets -->
134
   <extension
164
   <extension
135
         point="org.eclipse.ui.actionSets">
165
         point="org.eclipse.ui.actionSets">
(-)src/org/eclipse/ui/texteditor/AbstractTextEditor.java (-2 / +12 lines)
Lines 3730-3744 Link Here
3730
		action.setActionDefinitionId(ITextEditorActionDefinitionIds.MOVE_LINES_DOWN);
3730
		action.setActionDefinitionId(ITextEditorActionDefinitionIds.MOVE_LINES_DOWN);
3731
		setAction(ITextEditorActionConstants.MOVE_LINE_DOWN, action);
3731
		setAction(ITextEditorActionConstants.MOVE_LINE_DOWN, action);
3732
		
3732
		
3733
		action = new CaseAction(EditorMessages.getResourceBundle(), "Editor.UpperCase.", this, true); //$NON-NLS-1$
3733
		action = new UpperLowerCaseAction(EditorMessages.getResourceBundle(), "Editor.UpperCase.", this, true); //$NON-NLS-1$
3734
		action.setHelpContextId(IAbstractTextEditorHelpContextIds.UPPER_CASE_ACTION);
3734
		action.setHelpContextId(IAbstractTextEditorHelpContextIds.UPPER_CASE_ACTION);
3735
		action.setActionDefinitionId(ITextEditorActionDefinitionIds.UPPER_CASE);
3735
		action.setActionDefinitionId(ITextEditorActionDefinitionIds.UPPER_CASE);
3736
		setAction(ITextEditorActionConstants.UPPER_CASE, action);
3736
		setAction(ITextEditorActionConstants.UPPER_CASE, action);
3737
		
3737
		
3738
		action = new CaseAction(EditorMessages.getResourceBundle(), "Editor.LowerCase.", this, false); //$NON-NLS-1$
3738
		action = new UpperLowerCaseAction(EditorMessages.getResourceBundle(), "Editor.LowerCase.", this, false); //$NON-NLS-1$
3739
		action.setHelpContextId(IAbstractTextEditorHelpContextIds.LOWER_CASE_ACTION);
3739
		action.setHelpContextId(IAbstractTextEditorHelpContextIds.LOWER_CASE_ACTION);
3740
		action.setActionDefinitionId(ITextEditorActionDefinitionIds.LOWER_CASE);
3740
		action.setActionDefinitionId(ITextEditorActionDefinitionIds.LOWER_CASE);
3741
		setAction(ITextEditorActionConstants.LOWER_CASE, action);
3741
		setAction(ITextEditorActionConstants.LOWER_CASE, action);
3742
		
3743
		action = new InvertCaseAction(EditorMessages.getResourceBundle(), "Editor.InvertCase.", this); //$NON-NLS-1$
3744
		action.setHelpContextId(IAbstractTextEditorHelpContextIds.INVERT_CASE_ACTION);
3745
		action.setActionDefinitionId(ITextEditorActionDefinitionIds.INVERT_CASE);
3746
		setAction(ITextEditorActionConstants.INVERT_CASE, action);
3747
		
3748
		action = new CapitalizeCaseAction(EditorMessages.getResourceBundle(), "Editor.CapitalizeCase.", this); //$NON-NLS-1$
3749
		action.setHelpContextId(IAbstractTextEditorHelpContextIds.INVERT_CASE_ACTION);
3750
		action.setActionDefinitionId(ITextEditorActionDefinitionIds.CAPITALIZE_CASE);
3751
		setAction(ITextEditorActionConstants.INVERT_CASE, action);		
3742
		
3752
		
3743
		action = new SmartEnterAction(EditorMessages.getResourceBundle(), "Editor.SmartEnter.", this, false); //$NON-NLS-1$
3753
		action = new SmartEnterAction(EditorMessages.getResourceBundle(), "Editor.SmartEnter.", this, false); //$NON-NLS-1$
3744
		action.setHelpContextId(IAbstractTextEditorHelpContextIds.SMART_ENTER_ACTION);
3754
		action.setHelpContextId(IAbstractTextEditorHelpContextIds.SMART_ENTER_ACTION);
(-)src/org/eclipse/ui/texteditor/CaseAction.java (-15 / +17 lines)
Lines 7-12 Link Here
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Sebastian Davids <sdavids@gmx.de> - bug 8515
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.texteditor;
12
package org.eclipse.ui.texteditor;
12
13
Lines 21-37 Link Here
21
import org.eclipse.swt.graphics.Point;
22
import org.eclipse.swt.graphics.Point;
22
23
23
/**
24
/**
24
 * Action that converts the current selection to lower case.
25
 * Action that converts the current selection to a different case.
25
 * @since 3.0
26
 * @since 3.0
26
 */
27
 */
27
public class CaseAction extends ResourceAction implements IUpdate {
28
public abstract class CaseAction extends ResourceAction implements IUpdate {
28
29
29
	/** The editor we are working on. */
30
	/** The editor we are working on. */
30
	private AbstractTextEditor fEditor;
31
	private AbstractTextEditor fEditor;
31
32
32
	/** <code>true</code> if this action converts to upper case, <code>false</code> otherwise. */
33
	private boolean fToUpper;
34
35
	/**
33
	/**
36
	 * Creates and initializes the action for the given text editor.
34
	 * Creates and initializes the action for the given text editor.
37
	 * The action configures its visual representation from the given resource
35
	 * The action configures its visual representation from the given resource
Lines 41-54 Link Here
41
	 * @param prefix a prefix to be prepended to the various resource keys
39
	 * @param prefix a prefix to be prepended to the various resource keys
42
	 *   (described in <code>ResourceAction</code> constructor), or  <code>null</code> if none
40
	 *   (described in <code>ResourceAction</code> constructor), or  <code>null</code> if none
43
	 * @param editor the text editor
41
	 * @param editor the text editor
44
	 * @param toUpper <code>true</code> if this is an uppercase action, <code>false</code> otherwise.
45
	 * 
46
	 * @see ResourceAction#ResourceAction
42
	 * @see ResourceAction#ResourceAction
47
	 */
43
	 */
48
	public CaseAction(ResourceBundle bundle, String prefix, AbstractTextEditor editor, boolean toUpper) {
44
	public CaseAction(ResourceBundle bundle, String prefix, AbstractTextEditor editor) {
49
		super(bundle, prefix);
45
		super(bundle, prefix);
50
		fEditor= editor;
46
		fEditor= editor;
51
		fToUpper= toUpper;
52
		update();
47
		update();
53
	}
48
	}
54
49
Lines 77-87 Link Here
77
		Point sel= viewer.getSelectedRange();
72
		Point sel= viewer.getSelectedRange();
78
		if (sel == null)
73
		if (sel == null)
79
			return;
74
			return;
80
75
		int selY = sel.y;
81
		try {
76
		try {
82
			// if the selection is emtpy, we select the word / string using the viewer's 
77
			// if the selection is emtpy, we select the word / string using the viewer's 
83
			// doubleclick strategy
78
			// doubleclick strategy
84
			if (sel.y == 0)  {
79
			if (selY == 0)  {
85
				SourceViewerConfiguration svc= fEditor.getSourceViewerConfiguration(); // never null when viewer instantiated
80
				SourceViewerConfiguration svc= fEditor.getSourceViewerConfiguration(); // never null when viewer instantiated
86
				String partition= document.getContentType(sel.x);
81
				String partition= document.getContentType(sel.x);
87
				ITextDoubleClickStrategy dcs= svc.getDoubleClickStrategy(viewer, partition);
82
				ITextDoubleClickStrategy dcs= svc.getDoubleClickStrategy(viewer, partition);
Lines 89-102 Link Here
89
					dcs.doubleClicked(viewer);
84
					dcs.doubleClicked(viewer);
90
					sel= viewer.getSelectedRange();
85
					sel= viewer.getSelectedRange();
91
				} 
86
				} 
92
				if (sel.y == 0)
87
				if (selY == 0)
93
					return;	// if the selection is still empty, we're done
88
					return;	// if the selection is still empty, we're done
94
			}
89
			}
95
90
96
			String target= document.get(sel.x, sel.y);
91
			String target= document.get(sel.x, selY);
97
			String replacement= (fToUpper ? target.toUpperCase() : target.toLowerCase());
92
			//bug 8515
93
			String replacement= replace(target);
98
			if (!target.equals(replacement)) {
94
			if (!target.equals(replacement)) {
99
				document.replace(sel.x, target.length(), replacement);
95
				document.replace(sel.x, target.length(), replacement);
96
				//the replacement might be larger than the original
97
				int adjustment = replacement.length() - target.length();
98
				if (adjustment > 0)
99
					selY += adjustment;
100
			}
100
			}
101
		} catch (BadLocationException x) {
101
		} catch (BadLocationException x) {
102
			// ignore and return
102
			// ignore and return
Lines 104-110 Link Here
104
		}
104
		}
105
105
106
		// reinstall selection and move it into view
106
		// reinstall selection and move it into view
107
		viewer.setSelectedRange(sel.x, sel.y);
107
		viewer.setSelectedRange(sel.x, selY);
108
		// don't use the viewer's reveal feature in order to avoid jumping around		
108
		// don't use the viewer's reveal feature in order to avoid jumping around		
109
		st.showSelection();
109
		st.showSelection();
110
	}
110
	}
Lines 123-126 Link Here
123
		}
123
		}
124
		setEnabled(enabled);
124
		setEnabled(enabled);
125
	}
125
	}
126
	
127
	protected abstract String replace(String original);
126
}
128
}
(-)src/org/eclipse/ui/texteditor/EditorMessages.properties (+9 lines)
Lines 286-291 Link Here
286
Editor.LowerCase.image=
286
Editor.LowerCase.image=
287
Editor.LowerCase.description=Changes the selection to lower case
287
Editor.LowerCase.description=Changes the selection to lower case
288
288
289
Editor.InvertCase.label=Invert Case
290
Editor.InvertCase.tooltip=Inverts the case of the selection
291
Editor.InvertCase.image=
292
Editor.InvertCase.description=Inverts the case of the selection
293
294
Editor.CapitalizeCase.label=Capitalize Case
295
Editor.CapitalizeCase.tooltip=Capitalizes the selection
296
Editor.CapitalizeCase.image=
297
Editor.CapitalizeCase.description=Capitalizes the selection
289
298
290
## Status line ##
299
## Status line ##
291
300
(-)src/org/eclipse/ui/texteditor/IAbstractTextEditorHelpContextIds.java (+14 lines)
Lines 282-287 Link Here
282
282
283
	/**
283
	/**
284
	 * Help context id for the action.
284
	 * Help context id for the action.
285
	 * Value: <code>"org.eclipse.ui.invert_case_action_context"</code>
286
	 * @since 3.0
287
	 */
288
	public static final String INVERT_CASE_ACTION= PREFIX + "invert_case" + ACTION_POSTFIX; //$NON-NLS-1$
289
	
290
	/**
291
	 * Help context id for the action.
292
	 * Value: <code>"org.eclipse.ui.capitalize_case_action_context"</code>
293
	 * @since 3.0
294
	 */
295
	public static final String CAPITALIZE_CASE_ACTION= PREFIX + "capitalize_case" + ACTION_POSTFIX; //$NON-NLS-1$	
296
	
297
	/**
298
	 * Help context id for the action.
285
	 * Value: <code>"org.eclipse.ui.smart_enter_action_context"</code>
299
	 * Value: <code>"org.eclipse.ui.smart_enter_action_context"</code>
286
	 * @since 3.0
300
	 * @since 3.0
287
	 */
301
	 */
(-)src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java (+14 lines)
Lines 196-201 Link Here
196
	 * @since 3.0
196
	 * @since 3.0
197
	 */
197
	 */
198
	static final String LOWER_CASE= "LowerCase"; //$NON-NLS-1$
198
	static final String LOWER_CASE= "LowerCase"; //$NON-NLS-1$
199
200
	/** 
201
	 * Name of the action to invert a selection's case 
202
	 * Value: <code>"LowerCase"</code>
203
	 * @since 3.0
204
	 */
205
	static final String INVERT_CASE= "InvertCase"; //$NON-NLS-1$
206
		
207
	/** 
208
	 * Name of the action to turn a selection to capitalized case 
209
	 * Value: <code>"LowerCase"</code>
210
	 * @since 3.0
211
	 */
212
	static final String CAPITALIZE_CASE= "CapitalizeCase"; //$NON-NLS-1$
199
	
213
	
200
	/** 
214
	/** 
201
	 * Name of the action to find next. 
215
	 * Name of the action to find next. 
(-)src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java (-2 / +15 lines)
Lines 111-125 Link Here
111
	 * @since 3.0
111
	 * @since 3.0
112
	 */
112
	 */
113
	public static final String UPPER_CASE= "org.eclipse.ui.edit.text.upperCase"; //$NON-NLS-1$
113
	public static final String UPPER_CASE= "org.eclipse.ui.edit.text.upperCase"; //$NON-NLS-1$
114
115
	/**
116
	 * Action definition id of the upper case action.
117
	 * Value: <code>"org.eclipse.ui.edit.text.lowerCase"</code>
118
	 * @since 3.0
119
	 */
120
	public static final String LOWER_CASE= "org.eclipse.ui.edit.text.lowerCase"; //$NON-NLS-1$
121
		
122
	/**
123
	 * Action definition id of the lower case action.
124
	 * Value: <code>"org.eclipse.ui.edit.text.lowerCase"</code>
125
	 * @since 3.0
126
	 */
127
	public static final String INVERT_CASE= "org.eclipse.ui.edit.text.invertCase"; //$NON-NLS-1$
114
	
128
	
115
	/**
129
	/**
116
	 * Action definition id of the lower case action.
130
	 * Action definition id of the lower case action.
117
	 * Value: <code>"org.eclipse.ui.edit.text.lowerCase"</code>
131
	 * Value: <code>"org.eclipse.ui.edit.text.lowerCase"</code>
118
	 * @since 3.0
132
	 * @since 3.0
119
	 */
133
	 */
120
	public static final String LOWER_CASE= "org.eclipse.ui.edit.text.lowerCase"; //$NON-NLS-1$
134
	public static final String CAPITALIZE_CASE= "org.eclipse.ui.edit.text.capitalizeCase"; //$NON-NLS-1$
121
	
135
	
122
123
	// navigation
136
	// navigation
124
	
137
	
125
	/**
138
	/**
(-)src/org/eclipse/ui/internal/texteditor/Strings.java (+147 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     Sebastian Davids <sdavids@gmx.de> - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.texteditor;
12
13
import java.util.StringTokenizer;
14
15
/**
16
 * Helper class to provide String manipulation functions not available in standard JDK.
17
 */
18
public class Strings {
19
20
	private Strings() {}
21
22
	/** 
23
	 * Inverts the case of each letter of the given <code>String</code>.
24
	 * <p>
25
	 * This methods handles the special cases where a lower case letter will be
26
	 * represented as two upper case letters, e.g. German &szlig; -> SS.
27
	 * <p>
28
	 * <strong>Attention:</strong>
29
	 * <ul>
30
	 * 	<li>The length of the inverted string may be greater than the original
31
	 * 	one's.</li>
32
	 * 	<li>The inversion might not be reversible, e.g. German <em>Ma&szlig;e</em>
33
	 * 	will be inverted to <em>mASSE</em>; but inverting <em>mASSE</em> will
34
	 * 	produce <em>Masse</em>.</li>
35
	 * </ul>
36
	 * 
37
	 * @param s the <code>String</code> to be inverted.
38
	 * @return the inverted <code>String</code>
39
	 */
40
	public static String invertCase(String s) {
41
		if (s == null)
42
			return null;
43
44
		final int len= s.length();
45
46
		if (len == 0)
47
			return s;
48
49
		int i;
50
		char c;
51
52
		//skip to the first lower case letter
53
		for (i= 0; i < len; ++i) {
54
			c= s.charAt(i);
55
56
			if (Character.isLetter(c) && Character.isLowerCase(c))
57
				break;
58
		}
59
60
		if (i == len)
61
			return s.toLowerCase();
62
63
		StringBuffer result= new StringBuffer(len);
64
65
		//append characters before first lower case letter
66
		result.append(s.substring(0, i).toLowerCase());
67
68
		String cS;
69
70
		for (; i < len; ++i) {
71
			c= s.charAt(i);
72
73
			if (Character.isLetter(c)) {
74
				if (Character.isLowerCase(c)) {
75
					cS= ("" + c).toUpperCase(); //$NON-NLS-1$
76
77
					result.append(cS);
78
				} else
79
					result.append(Character.toLowerCase(c));
80
			} else
81
				result.append(c);
82
		}
83
84
		return result.toString();
85
	}
86
87
	/** 
88
	 * Capitalizes the given <code>String</code>.
89
	 * <p>
90
	 * Rules:
91
	 * <p>
92
	 * <ul>
93
	 *   <li>if the first character is a letter it will be upper case</li>
94
	 *   <li>each letter directly after a whitespace will be in upper case</li>
95
	 * </ul>
96
	 * 
97
	 * @param s the <code>String</code> to be capitalized.
98
	 * @return the capitalized <code>String</code>
99
	 */
100
	public static String capitalize(String s) {
101
		if (s == null)
102
			return null;
103
104
		final int len= s.length();
105
106
		if (len == 0)
107
			return s;
108
109
		if (len == 1)
110
			return s.toUpperCase();
111
112
		StringTokenizer st= new StringTokenizer(s, " \t\n\r\f", true); //$NON-NLS-1$
113
114
		StringBuffer result= new StringBuffer(s.length());
115
116
		while (st.hasMoreTokens())
117
			upperCaseFirstLetter(result, st.nextToken());
118
119
		return result.toString();
120
	}
121
122
	/**
123
	 * Converts the first character of <code>token</code> to upper case if it is
124
	 * a letter and append the converted <code>String</code> to <code>buf</code>;
125
	 * if the first character is not a letter, <code>token</code> will be
126
	 * appended to <code>buf</code> without any processing.
127
	 * 
128
	 * @param buf the <code>StringBuffer</code> the processed <code>token</code> will be appended to.
129
	 * @param token the token.
130
	 */
131
	private static void upperCaseFirstLetter(StringBuffer buf, String token) {
132
		//assert token.length() != 0;
133
		char firstChar= token.charAt(0);
134
135
		if (!Character.isLetter(firstChar)) {
136
			buf.append(token);
137
			return;
138
		}
139
140
		buf.append(("" + firstChar).toUpperCase()); //$NON-NLS-1$
141
142
		int len= token.length();
143
144
		if (len > 1)
145
			buf.append(token.substring(1, len));
146
	}
147
}
(-)src/org/eclipse/ui/internal/texteditor/StringsTest.java (+166 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.texteditor;
12
13
import junit.framework.Test;
14
import junit.framework.TestCase;
15
import junit.framework.TestSuite;
16
17
import org.eclipse.jdt.internal.corext.util.Strings;
18
19
public class StringsTest extends TestCase {
20
21
		public void testInvertCase() {
22
			assertEquals("null", null, Strings.invertCase(null)); //$NON-NLS-1$
23
	
24
			assertEquals("empty", //$NON-NLS-1$ 
25
			"", //$NON-NLS-1$
26
			Strings.invertCase("")); //$NON-NLS-1$
27
	
28
			assertEquals("&ABC1", //$NON-NLS-1$
29
			"&abc1", //$NON-NLS-1$ 
30
			Strings.invertCase("&ABC1")); //$NON-NLS-1$
31
	
32
			assertEquals("A", //$NON-NLS-1$
33
			"a", //$NON-NLS-1$ 
34
			Strings.invertCase("A")); //$NON-NLS-1$
35
	
36
			assertEquals("AAA", //$NON-NLS-1$
37
			"aaa", //$NON-NLS-1$ 
38
			Strings.invertCase("AAA")); //$NON-NLS-1$
39
	
40
			assertEquals("b", //$NON-NLS-1$
41
			"B", //$NON-NLS-1$ 
42
			Strings.invertCase("b")); //$NON-NLS-1$
43
	
44
			assertEquals("aB", //$NON-NLS-1$
45
			"Ab", //$NON-NLS-1$ 
46
			Strings.invertCase("aB")); //$NON-NLS-1$
47
	
48
			assertEquals("Ab", //$NON-NLS-1$
49
			"aB", //$NON-NLS-1$ 
50
			Strings.invertCase("Ab")); //$NON-NLS-1$
51
	
52
			assertEquals("aBa", //$NON-NLS-1$
53
			"AbA", //$NON-NLS-1$ 
54
			Strings.invertCase("aBa")); //$NON-NLS-1$
55
	
56
			assertEquals("AbA", //$NON-NLS-1$
57
			"aBa", //$NON-NLS-1$ 
58
			Strings.invertCase("AbA")); //$NON-NLS-1$
59
	
60
			assertEquals("Maße", //$NON-NLS-1$
61
			"mASSE", //$NON-NLS-1$
62
			Strings.invertCase("Maße")); //$NON-NLS-1$
63
	
64
			assertEquals("mASSE", //$NON-NLS-1$
65
			"Masse", //$NON-NLS-1$
66
			Strings.invertCase("mASSE")); //$NON-NLS-1$
67
	
68
			assertEquals("&ßö\t\";AÜ4", //$NON-NLS-1$ 
69
			"&SSÖ\t\";aü4", //$NON-NLS-1$ 
70
			Strings.invertCase("&ßö\t\";AÜ4")); //$NON-NLS-1$
71
		}
72
 	
73
	
74
		public void testCapitalize() {
75
			assertEquals("null", null, Strings.capitalize(null)); //$NON-NLS-1$
76
	
77
			assertEquals("empty", //$NON-NLS-1$ 
78
			"", //$NON-NLS-1$
79
			Strings.capitalize("")); //$NON-NLS-1$
80
	
81
			assertEquals("a", //$NON-NLS-1$
82
			"A", //$NON-NLS-1$ 
83
			Strings.capitalize("a")); //$NON-NLS-1$
84
	
85
			assertEquals("A", //$NON-NLS-1$
86
			"A", //$NON-NLS-1$ 
87
			Strings.capitalize("A")); //$NON-NLS-1$
88
	
89
			assertEquals("ß", //$NON-NLS-1$
90
			"SS", //$NON-NLS-1$ 
91
			Strings.capitalize("ß")); //$NON-NLS-1$
92
 
93
			assertEquals("ab", //$NON-NLS-1$
94
			"Ab", //$NON-NLS-1$ 
95
			Strings.capitalize("Ab")); //$NON-NLS-1$
96
	
97
			assertEquals("1a", //$NON-NLS-1$
98
			"1a", //$NON-NLS-1$ 
99
			Strings.capitalize("1a")); //$NON-NLS-1$
100
	
101
			assertEquals(" a", //$NON-NLS-1$
102
			" A", //$NON-NLS-1$ 
103
			Strings.capitalize(" a")); //$NON-NLS-1$	
104
	
105
			assertEquals("a ", //$NON-NLS-1$
106
			"A ", //$NON-NLS-1$ 
107
			Strings.capitalize("a ")); //$NON-NLS-1$
108
	
109
			assertEquals(" A", //$NON-NLS-1$
110
			" A", //$NON-NLS-1$ 
111
			Strings.capitalize(" A")); //$NON-NLS-1$				
112
	
113
			assertEquals("A ", //$NON-NLS-1$
114
			"A ", //$NON-NLS-1$ 
115
			Strings.capitalize("A ")); //$NON-NLS-1$				
116
	
117
			assertEquals(" ß", //$NON-NLS-1$
118
			" SS", //$NON-NLS-1$ 
119
			Strings.capitalize(" ß")); //$NON-NLS-1$
120
	
121
			assertEquals("ß ", //$NON-NLS-1$
122
			"SS ", //$NON-NLS-1$ 
123
			Strings.capitalize("ß ")); //$NON-NLS-1$
124
	
125
			assertEquals(" ab", //$NON-NLS-1$
126
			" Ab", //$NON-NLS-1$ 
127
			Strings.capitalize(" ab")); //$NON-NLS-1$	
128
	
129
			assertEquals(" 1a", //$NON-NLS-1$
130
			" 1a", //$NON-NLS-1$ 
131
			Strings.capitalize(" 1a")); //$NON-NLS-1$	
132
	
133
			assertEquals("\\ta", //$NON-NLS-1$
134
			"\tA", //$NON-NLS-1$ 
135
			Strings.capitalize("\ta")); //$NON-NLS-1$	
136
	
137
			assertEquals("a\\t", //$NON-NLS-1$
138
			"A\t", //$NON-NLS-1$ 
139
			Strings.capitalize("a\t")); //$NON-NLS-1$	
140
	
141
			assertEquals("\\tA", //$NON-NLS-1$
142
			"\tA", //$NON-NLS-1$ 
143
			Strings.capitalize("\tA")); //$NON-NLS-1$				
144
	
145
			assertEquals("A\\t", //$NON-NLS-1$
146
			"A\t", //$NON-NLS-1$ 
147
			Strings.capitalize("A\t")); //$NON-NLS-1$		
148
	
149
			assertEquals("\\t1ab", //$NON-NLS-1$
150
		"\t1ab", //$NON-NLS-1$ 
151
			Strings.capitalize("\t1ab")); //$NON-NLS-1$	
152
	
153
			assertEquals("\\t1a", //$NON-NLS-1$
154
		"\t1a", //$NON-NLS-1$ 
155
			Strings.capitalize("\t1a")); //$NON-NLS-1$	
156
	
157
			assertEquals("a\\tb cd", //$NON-NLS-1$
158
			"A\tBa SSd", //$NON-NLS-1$ 
159
			Strings.capitalize("a\tba ßd")); //$NON-NLS-1$	
160
		}
161
	
162
	public static Test suite() {
163
		return new TestSuite(StringsTest.class);
164
	}
165
}
166
(-)src/org/eclipse/ui/texteditor/CapitalizeCaseAction.java (+46 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     Sebastian Davids <sdavids@gmx.de> - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.texteditor;
12
13
import java.util.ResourceBundle;
14
15
import org.eclipse.ui.internal.texteditor.Strings;
16
17
/**
18
 * Action that capitalizes the current selection.
19
 * @since 3.0
20
 */
21
public class CapitalizeCaseAction extends CaseAction {
22
23
	/**
24
	 * Creates and initializes the action for the given text editor.
25
	 * The action configures its visual representation from the given resource
26
	 * bundle. 
27
	 * 
28
	 * @param bundle the resource bundle
29
	 * @param prefix a prefix to be prepended to the various resource keys
30
	 *   (described in <code>ResourceAction</code> constructor), or  <code>null</code> if none
31
	 * @param editor the text editor
32
	 * @param toUpper <code>true</code> if this is an uppercase action, <code>false</code> otherwise.
33
	 * 
34
	 * @see ResourceAction#ResourceAction
35
	 */
36
	public CapitalizeCaseAction(ResourceBundle bundle, String prefix, AbstractTextEditor editor) {
37
		super(bundle, prefix, editor);
38
	}
39
40
	/* (non-Javadoc)
41
	 * @see org.eclipse.ui.texteditor.CaseAction#replace(java.lang.String)
42
	 */	
43
	protected String replace(String original) {
44
		return Strings.capitalize(original);
45
	}
46
}
(-)src/org/eclipse/ui/texteditor/InvertCaseAction.java (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     Sebastian Davids <sdavids@gmx.de> - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.texteditor;
12
13
import java.util.ResourceBundle;
14
15
import org.eclipse.ui.internal.texteditor.Strings;
16
17
/**
18
 * Action that inverts the case of the current selection.
19
 * @since 3.0
20
 */
21
public class InvertCaseAction extends CaseAction {
22
23
	/**
24
	 * Creates and initializes the action for the given text editor.
25
	 * The action configures its visual representation from the given resource bundle. 
26
	 * 
27
	 * @param bundle the resource bundle
28
	 * @param prefix a prefix to be prepended to the various resource keys
29
	 *   (described in <code>ResourceAction</code> constructor), or  <code>null</code> if none
30
	 * @param editor the text editor
31
	 * 
32
	 * @see ResourceAction#ResourceAction
33
	 */
34
	public InvertCaseAction(ResourceBundle bundle, String prefix, AbstractTextEditor editor) {
35
		super(bundle, prefix, editor);
36
	}
37
38
	/* (non-Javadoc)
39
	 * @see org.eclipse.ui.texteditor.CaseAction#replace(java.lang.String)
40
	 */
41
	protected String replace(String original) {
42
		return Strings.invertCase(original);
43
	}
44
}
(-)src/org/eclipse/ui/texteditor/UpperLowerCaseAction.java (+47 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     Sebastian Davids <sdavids@gmx.de> - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.texteditor;
12
13
import java.util.ResourceBundle;
14
15
/**
16
 * Action that converts the current selection to upper or lower case.
17
 * @since 3.0
18
 */
19
public class UpperLowerCaseAction extends CaseAction {
20
21
	/** <code>true</code> if this action converts to upper case, <code>false</code> otherwise. */
22
	private boolean fToUpper;
23
24
	/**
25
	 * Creates and initializes the action for the given text editor.
26
	 * The action configures its visual representation from the given resource bundle. 
27
	 * 
28
	 * @param bundle the resource bundle
29
	 * @param prefix a prefix to be prepended to the various resource keys
30
	 *   (described in <code>ResourceAction</code> constructor), or  <code>null</code> if none
31
	 * @param editor the text editor
32
	 * @param toUpper <code>true</code> if this is an uppercase action, <code>false</code> otherwise.
33
	 * 
34
	 * @see ResourceAction#ResourceAction
35
	 */
36
	public UpperLowerCaseAction(ResourceBundle bundle, String prefix, AbstractTextEditor editor, boolean toUpper) {
37
		super(bundle, prefix, editor);
38
		fToUpper= toUpper;
39
	}
40
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.ui.texteditor.CaseAction#replace(java.lang.String)
43
	 */	
44
	protected String replace(String original) {
45
		return (fToUpper ? original.toUpperCase() : original.toLowerCase());
46
	}
47
}

Return to bug 8518