Example usage for java.lang StringBuilder charAt

List of usage examples for java.lang StringBuilder charAt

Introduction

In this page you can find the example usage for java.lang StringBuilder charAt.

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:org.exoplatform.calendar.ws.CalendarRestApi.java

private String buildFullUrl(UriInfo uriInfo, int offset, int limit, long fullSize) {
    if (fullSize <= 0) {
        return "";
    }//from   ww w. j  a  v  a2s  . c  om
    offset = offset < 0 ? 0 : offset;

    long prev = offset - limit;
    prev = offset > 0 && prev < 0 ? 0 : prev;
    long prevLimit = offset - prev;
    //
    StringBuilder sb = new StringBuilder();
    if (prev >= 0) {
        sb.append("<").append(uriInfo.getAbsolutePath()).append("?offset=");
        sb.append(prev).append("&limit=").append(prevLimit).append(">").append(Utils.SEMICOLON)
                .append("rel=\"previous\",");
    }

    long next = offset + limit;
    //
    if (next < fullSize) {
        sb.append("<").append(uriInfo.getAbsolutePath()).append("?offset=");
        sb.append(next).append("&limit=").append(limit).append(">").append(Utils.SEMICOLON)
                .append("rel=\"next\",");
    }

    //first page
    long firstLimit = limit > fullSize ? fullSize : limit;
    sb.append("<").append(uriInfo.getAbsolutePath()).append("?offset=0&limit=").append(firstLimit).append(">");
    sb.append(Utils.SEMICOLON).append("rel=\"first\",");
    //last page
    long lastIndex = fullSize - (fullSize % firstLimit);
    if (lastIndex == fullSize) {
        lastIndex = fullSize - firstLimit;
    }
    if (lastIndex > 0) {
        sb.append("<").append(uriInfo.getAbsolutePath()).append("?offset=").append(lastIndex);
        sb.append("&limit=").append(fullSize - lastIndex).append(">");
        sb.append(Utils.SEMICOLON).append("rel=\"last\"");
    }
    if (sb.charAt(sb.length() - 1) == ',') {
        sb.deleteCharAt(sb.length() - 1);
    }

    return sb.toString();
}

From source file:com.arksoft.epamms.ZGlobal1_Operation.java

public int RemoveLeadingZerosFromAttrib(View view, String stringEntity, String stringAttribute) {
    StringBuilder sb = new StringBuilder(256);
    MutableInt i = new MutableInt(0);
    int k;//  www .  j a  v a  2 s .co m

    // Remove any leading zeros from the attribute.

    GetVariableFromAttribute(sb, i, zTYPE_STRING, 253, view, stringEntity, stringAttribute, "", 0);
    if (sb.charAt(0) == '0') {
        k = 1;

        while (sb.charAt(k) == '0')
            k++;

        SetAttributeFromString(view, stringEntity, stringAttribute, sb.substring(k));
    }

    return 0;

}

From source file:com.arksoft.epamms.ZGlobal1_Operation.java

public int RemoveLeadingBlanksFromAttrib(View view, String stringEntity, String stringAttribute) {
    StringBuilder sb = new StringBuilder(256);
    MutableInt i = new MutableInt(0);
    int k;/*from  www  . java 2 s  .c  om*/

    // Remove any leading blanks from the attribute.

    GetVariableFromAttribute(sb, i, zTYPE_STRING, 253, view, stringEntity, stringAttribute, "", 0);
    if (sb.charAt(0) == ' ') {
        k = 1;

        while (sb.charAt(k) == ' ')
            k++;

        SetAttributeFromString(view, stringEntity, stringAttribute, sb.substring(k));
    }

    return 0;

}

From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.java

private void printNode(final StringBuilder buffer, final DomNode node, final boolean html) {
    if (node instanceof DomComment) {
        if (html) {
            // Remove whitespace sequences.
            final String s = PRINT_NODE_PATTERN.matcher(node.getNodeValue()).replaceAll(" ");
            buffer.append("<!--").append(s).append("-->");
        }/*from w w w . ja  v  a 2  s.c  o  m*/
    } else if (node instanceof DomCharacterData) {
        // Remove whitespace sequences, possibly escape XML characters.
        String s = node.getNodeValue();
        if (html) {
            s = com.gargoylesoftware.htmlunit.util.StringUtils.escapeXmlChars(s);
        }
        buffer.append(s);
    } else if (html) {
        final DomElement element = (DomElement) node;
        final Element scriptObject = (Element) node.getScriptableObject();
        final String tag = element.getTagName();

        HTMLElement htmlElement = null;
        if (scriptObject instanceof HTMLElement) {
            htmlElement = (HTMLElement) scriptObject;
        }
        buffer.append("<").append(tag);
        // Add the attributes. IE does not use quotes, FF does.
        for (final DomAttr attr : element.getAttributesMap().values()) {
            if (!attr.getSpecified()) {
                continue;
            }

            final String name = attr.getName();
            final String value = PRINT_NODE_QUOTE_PATTERN.matcher(attr.getValue()).replaceAll("&quot;");
            buffer.append(' ').append(name).append("=");
            buffer.append("\"");
            buffer.append(value);
            buffer.append("\"");
        }
        buffer.append(">");
        // Add the children.
        final boolean isHtml = html && !(scriptObject instanceof HTMLScriptElement)
                && !(scriptObject instanceof HTMLStyleElement);
        printChildren(buffer, node, isHtml);
        if (null == htmlElement || !htmlElement.isEndTagForbidden()) {
            buffer.append("</").append(tag).append(">");
        }
    } else {
        final HtmlElement element = (HtmlElement) node;
        if ("p".equals(element.getTagName())) {
            if (getBrowserVersion().hasFeature(JS_INNER_TEXT_CR_NL)) {
                buffer.append("\r\n"); // \r\n because it's to implement something IE specific
            } else {
                int i = buffer.length() - 1;
                while (i >= 0 && Character.isWhitespace(buffer.charAt(i))) {
                    i--;
                }
                buffer.setLength(i + 1);
                buffer.append("\n");
            }
        }
        if (!"script".equals(element.getTagName())) {
            printChildren(buffer, node, html);
        }
    }
}

From source file:self.philbrown.droidQuery.$.java

/** 
 * Capitalizes the first letter of the given string.
 * @param string the string whose first letter should be capitalized
 * @return the given string with its first letter capitalized
 * @throws NullPointerException if the string is null or empty
 *//* ww  w  . ja  v a 2s . c om*/
private String capitalize(String string) {
    if (string == null || string.trim().length() == 0)
        throw new NullPointerException("Cannot handle null or empty string");

    StringBuilder strBuilder = new StringBuilder(string);
    strBuilder.setCharAt(0, Character.toUpperCase(strBuilder.charAt(0)));
    return strBuilder.toString();
}

From source file:com.cohort.util.String2.java

/**
 * This removes white space characters at the beginning and end of a StringBuilder.
 *
 * @param sb a StringBuilder//  w  w  w . j av a2s .  c  o m
 * @return the same pointer to the StringBuilder for convenience
 */
public static StringBuilder trim(StringBuilder sb) {
    int po = 0;
    while (po < sb.length() && isWhite(sb.charAt(po)))
        po++;
    sb.delete(0, po);

    po = sb.length();
    while (po > 0 && isWhite(sb.charAt(po - 1)))
        po--;
    sb.delete(po, sb.length());
    return sb;
}

From source file:com.cohort.util.String2.java

/**
 * This converts the string to plain ascii (0..127).
 * Diacritics are stripped off high ASCII characters.
 * Some high ASCII characters are crudely converted to similar characters
 * (the conversion is always character-for-character, 
 * so the string length will be unchanged).
 * Other characters become '?'.//from  ww  w  . j a  v  a 2 s.co m
 * The result will be the same length as s.
 *
 * @param s
 * @return the string converted to plain ascii (0..127).
 */
public static String modifyToBeASCII(String s) {
    StringBuilder sb = new StringBuilder(s);
    int n = s.length();
    for (int i = 0; i < n; i++) {
        char ch = sb.charAt(i);
        if (ch <= 127) {
        } else if (ch >= 160 && ch <= 255)
            sb.setCharAt(i, plainASCII.charAt(ch - 160));
        else
            sb.setCharAt(i, '?');
    }
    return sb.toString();
}

From source file:com.arksoft.epamms.ZGlobal1_Operation.java

/**
   ////////////////////////////////////////////////////////////////////////////////////////////////////
   ///*from  ww w .  j a  v a2s.  co m*/
   //  Method Name: GetDataTypeForAttribute
   //
   //    Return the Data Type for an attribute
   //
   ////////////////////////////////////////////////////////////////////////////////////////////////////
   public int
   GetDataTypeForAttribute( String stringDataType,
                    View   lpView,
                    String entityName,
                    String attributeName )
   {
      LPVIEWENTITY lpEntityDef;
      LPVIEWATTRIB lpAttributeDef;
      int nRC;
        
      lpEntityDef = String zGETPTR( MiGetEntityDefForView( lpView, entityName ) );
      if ( lpEntityDef == 0 )
 return -16;
        
      // Position on attribute.
   #ifdef VIEWENTITY_OD
      lpAttributeDef = String zGETPTR( lpEntityDef->hFirstOD_Attrib );
      nRC = 1;
      while ( lpAttributeDef > 0 && nRC > 0 )
      {
 if ( zstrcmp( lpAttributeDef->stringName, attributeName ) == 0 )
    nRC = 0;
        
 if ( nRC > 0 )
    lpAttributeDef = String zGETPTR( lpAttributeDef->hNextOD_Attrib );
      }
   #else
      lpAttributeDef = String zGETPTR( lpEntityDef->hFirstAttributeDef );
      nRC = 1;
      while ( lpAttributeDef > 0 && nRC > 0 )
      {
 if ( zstrcmp( lpAttributeDef->stringName, attributeName ) == 0 )
    nRC = 0;
        
 if ( nRC > 0 )
    lpAttributeDef = String zGETPTR( lpAttributeDef->hNextAttributeDef );
      }
   #endif
      if ( nRC > 0 )
      {
 MessageSend( lpView, "", "GetDataTypeForAttribute",
              "The attribute specified was not found.",
              zMSGQ_OBJECT_CONSTRAINT_ERROR, 0 );
 return -1;
      }
        
      // Set single character datatype followed by a string terminator.
      *stringDataType = lpAttributeDef->hDomain->cType;
      *(stringDataType + 1) = 0;
        
      return 0;
   } // GetDataTypeForAttribute
**/

//
int ParseOutEntityAttribute(String entityDotAttribute, StringBuilder entityName, StringBuilder attributeName) {
    int k;
    int lSkipLth;

    // Initialize entityName and attributeName.
    entityName.replace(0, -1, entityDotAttribute);
    attributeName.delete(0, -1);
    // entityDotAttribute is pointing to the first character of the entity name on entry to this routine.
    // Parse out Entity Name

    for (k = 0; k < entityName.length(); k++) {
        char ch = entityName.charAt(k);
        if (ch == '.' || ch == ']' || ch == '}') {
            entityName.setCharAt(k, '\0');
            if (ch == '}')
                return -2;

            if (ch != ']') // there is an attribute, so keep going
            {
                int j = 0;
                k++;

                // Parse out Attribute Name
                ch = entityDotAttribute.charAt(k);
                while (ch != ']' && ch != '}') {
                    if (ch == '}')
                        return -2;

                    attributeName.setCharAt(j, ch);
                    j++;
                    k++;
                    ch = entityDotAttribute.charAt(k);
                }

                attributeName.setCharAt(k, '\0');
            }
        }
    }

    lSkipLth = k + 1; // TODO not sure this translation to java is exactly right for SkipLth
    return lSkipLth;
}

From source file:com.cohort.util.String2.java

/** This changes the character's case to sentence case 
 * (first letter and first letter after each period capitalized).  This is simplistic.
 */// w w  w  .  ja v  a 2 s. c  o m
public static String toSentenceCase(String s) {
    if (s == null)
        return null;
    int sLength = s.length();
    StringBuilder sb = new StringBuilder(s);
    boolean capNext = true;
    for (int i = 0; i < sLength; i++) {
        char c = sb.charAt(i);
        if (isLetter(c)) {
            if (capNext) {
                sb.setCharAt(i, Character.toUpperCase(c));
                capNext = false;
            } else {
                sb.setCharAt(i, Character.toLowerCase(c));
            }
        } else if (c == '.') {
            capNext = true;
        }
    }
    return sb.toString();
}

From source file:com.cohort.util.String2.java

/** This changes the characters case to title case (only letters after non-letters are
 * capitalized).  This is simplistic (it doesn't know about acronyms or pH or ...).
 *///from  w w  w  .  j  av a  2s  .c o  m
public static String toTitleCase(String s) {
    if (s == null)
        return null;
    int sLength = s.length();
    StringBuilder sb = new StringBuilder(s);
    char c = ' ', oc = ' ';
    for (int i = 0; i < sLength; i++) {
        oc = c;
        c = sb.charAt(i);
        if (isLetter(c))
            sb.setCharAt(i, isLetter(oc) ? Character.toLowerCase(c) : Character.toUpperCase(c));
    }
    return sb.toString();
}