Java String Unescape unescape(String theValue)

Here you can find the source of unescape(String theValue)

Description

Unescapes a string according to the rules for parameter escaping specified in the <a href="http://www.hl7.org/implement/standards/fhir/search.html#escaping">FHIR Specification Escaping Section</a>

License

Apache License

Declaration

public static String unescape(String theValue) 

Method Source Code

//package com.java2s;
/*/*  w  ww  .j  a v  a  2  s.  com*/
 * #%L
 * HAPI FHIR - Core Library
 * %%
 * Copyright (C) 2014 - 2016 University Health Network
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

public class Main {
    /**
     * Unescapes a string according to the rules for parameter escaping specified in the <a href="http://www.hl7.org/implement/standards/fhir/search.html#escaping">FHIR Specification Escaping
     * Section</a>
     */
    public static String unescape(String theValue) {
        if (theValue == null) {
            return theValue;
        }
        if (theValue.indexOf('\\') == -1) {
            return theValue;
        }

        StringBuilder b = new StringBuilder();

        for (int i = 0; i < theValue.length(); i++) {
            char next = theValue.charAt(i);
            if (next == '\\') {
                if (i == theValue.length() - 1) {
                    b.append(next);
                } else {
                    switch (theValue.charAt(i + 1)) {
                    case '$':
                    case ',':
                    case '|':
                    case '\\':
                        continue;
                    default:
                        b.append(next);
                    }
                }
            } else {
                b.append(next);
            }
        }

        return b.toString();
    }
}

Related

  1. unescape(String text)
  2. unescape(String text)
  3. unescape(String text)
  4. unescape(String text)
  5. unescape(String text)
  6. unescape(String val)
  7. unescape(String val, char quote)
  8. unescape(String value)
  9. unescape(String value)