Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 253180 Details for
Bug 465495
[BIDI] BidiUtils.applyBidiProcessing should work on String level (replace TextProcessor API)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
new API applyBidiProcessing(String string, String handlingType)
465495.patch (text/plain), 5.89 KB, created by
Moshe WAJNBERG
on 2015-05-05 11:25:51 EDT
(
hide
)
Description:
new API applyBidiProcessing(String string, String handlingType)
Filename:
MIME Type:
Creator:
Moshe WAJNBERG
Created:
2015-05-05 11:25:51 EDT
Size:
5.89 KB
patch
obsolete
>diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/util/BidiUtils.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/util/BidiUtils.java >index 38fa739..0d45018 100644 >--- a/bundles/org.eclipse.jface/src/org/eclipse/jface/util/BidiUtils.java >+++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/util/BidiUtils.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2012, 2014 IBM Corporation and others. >+ * Copyright (c) 2012, 2015 IBM Corporation 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 >@@ -14,6 +14,7 @@ > import java.util.HashMap; > import java.util.Map; > >+import org.eclipse.equinox.bidi.StructuredTextProcessor; > import org.eclipse.equinox.bidi.StructuredTextTypeHandlerFactory; > import org.eclipse.jface.internal.InternalPolicy; > import org.eclipse.swt.SWT; >@@ -142,6 +143,11 @@ > * The RLE char > */ > static final char RLE = 0x202B; >+ >+ /** >+ * The RLM char >+ */ >+ static final char RLM = 0x200F; > > /** > * The LRO char >@@ -537,4 +543,132 @@ > control.setTextDirection(textDir); > } > } >-} >+ >+ /** >+ * Applies bidi processing to the given string. >+ * >+ * <p> >+ * Possible values for <code>handlingType</code> are: >+ * <ul> >+ * <li>{@link BidiUtils#LEFT_TO_RIGHT}</li> >+ * <li>{@link BidiUtils#RIGHT_TO_LEFT}</li> >+ * <li>{@link BidiUtils#AUTO}</li> >+ * <li>{@link BidiUtils#BTD_DEFAULT}</li> >+ * <li>{@link BidiUtils#VISUAL_LEFT_TO_RIGHT}</li> >+ * <li>{@link BidiUtils#VISUAL_RIGHT_TO_LEFT}</li> >+ * <li>the <code>String</code> constants in >+ * {@link StructuredTextTypeHandlerFactory}</li> >+ * <li>if OSGi is running, the types that have been contributed to the >+ * <code>org.eclipse.equinox.bidi.bidiTypes</code> extension point.</li> >+ * </ul> >+ * <p> >+ * The 3 values {@link #LEFT_TO_RIGHT}, {@link #RIGHT_TO_LEFT}, and >+ * {@link #AUTO} are usable whether {@link #getBidiSupport() bidi support} >+ * is enabled or disabled. >+ * <p> >+ * The remaining values only have an effect if bidi support is enabled. >+ * <p> >+ * The 4 first values {@link #LEFT_TO_RIGHT}, {@link #RIGHT_TO_LEFT}, >+ * {@link #AUTO}, and {@link #BTD_DEFAULT} are for Base Text Direction (BTD) >+ * handling. The remaining values are for Structured Text handling. >+ * <p> >+ * <strong>Note:</strong> The Structured Text handling only works if the >+ * <code>org.eclipse.equinox.bidi</code> bundle is on the classpath! >+ * <p> >+ * <strong>Note:</strong> To deprocess the string you must use >+ * {@link BidiUtils#deprocessBidi(String)} for the 6 first values or >+ * {@link StructuredTextProcessor#deprocessTyped(String, String)} for the >+ * remaining values. >+ * </p> >+ * >+ * @param string >+ * the string >+ * @param handlingType >+ * the type of handling >+ * @return the bidi processed string >+ * @throws IllegalArgumentException >+ * if <code>handlingType</code> is not a known type identifier >+ */ >+ public static String applyBidiProcessing(String string, String handlingType) { >+ if (LEFT_TO_RIGHT.equals(handlingType)) { >+ return addUCC(string, false); >+ } else if (RIGHT_TO_LEFT.equals(handlingType)) { >+ return addUCC(string, true); >+ } else if (AUTO.equals(handlingType)) { >+ return addUCC(string, isRTLValue(string)); >+ >+ } else if (getBidiSupport()) { >+ if (BTD_DEFAULT.equals(handlingType)) { >+ if (LEFT_TO_RIGHT.equals(getTextDirection())) { >+ return addUCC(string, false); >+ } else if (RIGHT_TO_LEFT.equals(getTextDirection())) { >+ return addUCC(string, true); >+ } else if (AUTO.equals(getTextDirection())) { >+ return addUCC(string, isRTLValue(string)); >+ } >+ } else if (VISUAL_LEFT_TO_RIGHT.equals(handlingType)) { >+ return LRO + string + PDF; >+ } else if (VISUAL_RIGHT_TO_LEFT.equals(handlingType)) { >+ return RLO + string + PDF; >+ } else { >+ return StructuredTextProcessor.processTyped(string, handlingType); >+ } >+ } >+ return string; >+ } >+ >+ /** >+ * Strips off Unicode control characters from the given string. >+ * >+ * >+ * @param string >+ * the string >+ * @return the bidi deprocessed string >+ */ >+ public static String deprocessBidi(String string) { >+ StringBuffer header1 = new StringBuffer().append(LRM).append(LRE), >+ header2 = new StringBuffer().append(RLM).append(RLE); >+ StringBuffer tailer1 = new StringBuffer().append(LRM).append(PDF), >+ tailer2 = new StringBuffer().append(RLM).append(PDF); >+ >+ if ((string.startsWith(header1.toString()) && string.endsWith(tailer1.toString())) >+ || (string.startsWith(header2.toString()) && string.endsWith(tailer2.toString()))) { >+ return string.substring(2, string.length() - 2); >+ } else if ((string.charAt(0) == LRO || string.charAt(0) == RLO) && string.charAt(string.length() - 1) == PDF) { >+ return string.substring(1, string.length() - 1); >+ } >+ return string; >+ } >+ >+ private static String addUCC(String string, boolean isRTL) { >+ StringBuffer sb = new StringBuffer(); >+ if (isRTL) { >+ sb.append(RLM).append(RLE); >+ } else { >+ sb.append(LRM).append(LRE); >+ } >+ sb.append(string); >+ if (isRTL) { >+ sb.append(RLM); >+ } else { >+ sb.append(LRM); >+ } >+ sb.append(PDF); >+ return sb.toString(); >+ } >+ >+ private static boolean isRTLValue(String stringValue) { >+ for (int i = 0; i < stringValue.length(); i++) { >+ if (Character.getDirectionality(stringValue.charAt(i)) == Character.DIRECTIONALITY_RIGHT_TO_LEFT >+ || Character >+ .getDirectionality(stringValue.charAt(i)) == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC >+ || Character.getDirectionality(stringValue.charAt(i)) == Character.DIRECTIONALITY_ARABIC_NUMBER) >+ return true; >+ else if (Character.getDirectionality(stringValue.charAt(i)) == Character.DIRECTIONALITY_LEFT_TO_RIGHT) { >+ return false; >+ } >+ } >+ return false; >+ } >+ >+} >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 465495
:
253137
|
253158
|
253170
|
253180
|
253211
|
253432