Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2013 SAP AG 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. /
 
 package com.sap.core.odata.core.edm;
 
 
Implementation of the EDM simple type String.

Author(s):
SAP AG
 
 public class EdmString extends AbstractSimpleType {
 
   private static final EdmString instance = new EdmString();
   private static final Pattern PATTERN_ASCII = Pattern.compile("\\p{ASCII}*");
 
   public static EdmString getInstance() {
     return ;
   }
 
   @Override
   public Class<?> getDefaultType() {
     return String.class;
   }
 
   @Override
   protected <T> T internalValueOfString(final String valuefinal EdmLiteralKind literalKindfinal EdmFacets facetsfinal Class<T> returnTypethrows EdmSimpleTypeException {
     String result;
     if (literalKind == .) {
       if (value.length() >= 2 && value.startsWith("'") && value.endsWith("'")) {
         result = (value.substring(1, value.length() - 1)).replace("''""'");
       } else {
       }
     } else {
       result = value;
     }
 
     if (facets != null) {
       if (facets.isUnicode() != null && !facets.isUnicode() && !.matcher(result).matches()) {
       }
       if (facets.getMaxLength() != null && facets.getMaxLength() < result.length()) {
       }
     }
 
     if (returnType.isAssignableFrom(String.class)) {
       return returnType.cast(result);
     } else {
     }
   }
 
   @Override
   protected <T> String internalValueToString(final T valuefinal EdmLiteralKind literalKindfinal EdmFacets facetsthrows EdmSimpleTypeException {
     final String result = value instanceof String ? (Stringvalue : String.valueOf(value);
 
     if (facets != null) {
       if (facets.isUnicode() != null && !facets.isUnicode() && !.matcher(result).matches()
           || facets.getMaxLength() != null && facets.getMaxLength() < result.length()) {
       }
     }
 
     return result;
   }
 
   @Override
   public String toUriLiteral(final String literalthrows EdmSimpleTypeException {
     final StringBuilder uriLiteral = new StringBuilder("'");
     final int len = literal.length();
 
     for (int i = 0; i < leni++) {
       char c = literal.charAt(i);
       if (c == '\'') {
         uriLiteral.append("''");
       } else {
         uriLiteral.append(c);
       }
     }
     uriLiteral.append("'");
     return uriLiteral.toString();
  }
New to GrepCode? Check out our FAQ X