Example usage for java.lang CharSequence charAt

List of usage examples for java.lang CharSequence charAt

Introduction

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

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:com.mirth.connect.plugins.datatypes.hl7v2.XMLEncodedHL7Handler.java

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    logger.trace("ending element: " + localName);
    inElement = false;//from   w w w .j  ava  2  s .  c o  m

    String[] localNameArray = StringUtils.split(localName, ID_DELIMETER);

    /*
     * Once we see the closing of MSH.1 or MSH.2 tags, we know that the separator characters
     * have been added to the output buffer, so we can grab them and set the local variables.
     */
    if ((localNameArray.length == 1) && (localNameArray[0].equals(ER7Reader.MESSAGE_ROOT_ID))) {
        return;
    } else if (localNameArray.length == 2) {
        if (isHeaderSegment(localNameArray[0])) {
            if ((localNameArray[1].length() == 1) && (localNameArray[1].charAt(0) == '1')) {
                fieldSeparator = String.valueOf(output.charAt(output.length() - 1));
                return;
            } else if ((localNameArray[1].length() == 1) && (localNameArray[1].charAt(0) == '2')) {
                CharSequence separators = output.subSequence(4, output.length());
                componentSeparator = String.valueOf(separators.charAt(0));
                repetitionSeparator = String.valueOf(separators.charAt(1));
                escapeCharacter = separators.length() > 2 ? String.valueOf(separators.charAt(2)) : "";
                subcomponentSeparator = separators.length() > 3 ? String.valueOf(separators.charAt(3)) : "";
            }
        }
    }

    int currentDelimeterCount = localNameArray.length - 1;

    /*
     * We don't want to have tailing separators, so once we get to the last element of a nested
     * level, we delete the last character.
     */
    if (currentDelimeterCount > previousDelimeterCount) {
        previousDelimeterCount = currentDelimeterCount;
    } else if (currentDelimeterCount < previousDelimeterCount && previousDelimiterLength > 0) {
        output.deleteCharAt(output.length() - 1);
        previousDelimeterCount = currentDelimeterCount;
    }

    /*
     * The number of periods in the element tells us the level. So, MSH is at level 0, MSH.3 is
     * at level 1, MSH.3.1 at level 2, and so on. We can use this to determine which seperator
     * to append once the element is closed.
     * 
     * MIRTH-2078: Only add the last character if the root delimiter is 0 (HL7Message) or the
     * current element level is deeper than the root level. This only pertains to partial XML
     * messages where the root is a field or component.
     */
    if (rootLevel == 0 || currentDelimeterCount >= rootLevel) {
        switch (currentDelimeterCount) {
        case 0:
            output.append(segmentSeparator);
            break;
        case 1:
            output.append(fieldSeparator);
            break;
        case 2:
            output.append(componentSeparator);
            previousDelimiterLength = componentSeparator.length();
            break;
        case 3:
            output.append(subcomponentSeparator);
            previousDelimiterLength = subcomponentSeparator.length();
            break;
        default:
            break;
        }
    }
}

From source file:com.lm.im_huanxin.ui.widget.KJChatKeyboard.java

/**
 * =?= ??????1//from  w w  w . j  a v  a  2 s.c  o  m
 *
 * @param c
 * @return
 */
private long calculateLength(CharSequence c) {
    double len = 0;
    for (int i = 0; i < c.length(); i++) {
        int tmp = (int) c.charAt(i);
        if (tmp > 0 && tmp < 127) {
            len += 0.5;
        } else {
            len++;
        }
    }
    return Math.round(len);
}

From source file:jef.tools.ArrayUtils.java

/**
 * CharSequence????char/*w ww .  java  2 s.co m*/
 * ?CharBuffer,StringBuilder,StringbufferIterator???
 * 
 * @param e
 * @return
 */
public static Iterable<Character> toIterable(final CharSequence e) {
    return new Iterable<Character>() {
        public Iterator<Character> iterator() {
            return new Iterator<Character>() {
                int n = 0;

                public boolean hasNext() {
                    return n < e.length();
                }

                public Character next() {
                    return e.charAt(n++);
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}

From source file:netbeanstypescript.TSCodeCompletion.java

@Override
public String getPrefix(ParserResult info, int caretOffset, boolean upToOffset) {
    CharSequence seq = info.getSnapshot().getText();
    int i = caretOffset, j = i;
    while (i > 0 && Character.isJavaIdentifierPart(seq.charAt(i - 1))) {
        i--;//from  w w  w  .  j a v  a  2s.  c o  m
    }
    while (!upToOffset && j < seq.length() && Character.isJavaIdentifierPart(seq.charAt(j))) {
        j++;
    }
    return seq.subSequence(i, j).toString();
}

From source file:br.msf.commons.util.CharSequenceUtils.java

public static char firstChar(final CharSequence sequence) {
    ArgumentUtils.rejectIfNull(sequence);
    return sequence.charAt(0);
}

From source file:br.msf.commons.util.CharSequenceUtils.java

public static char lastChar(final CharSequence sequence) {
    ArgumentUtils.rejectIfNull(sequence);
    return sequence.charAt(length(sequence));
}

From source file:com.mirth.connect.model.converters.XMLEncodedHL7Handler.java

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    logger.trace("ending element: " + localName);
    inElement = false;/*from w  w w  . j a v a 2s  . c o m*/

    String[] localNameArray = StringUtils.split(localName, ID_DELIMETER);

    /*
     * Once we see the closing of MSH.1 or MSH.2 tags, we know that the
     * separator characters have been added to the output buffer, so we can
     * grab them and set the local variables.
     */
    if ((localNameArray.length == 1) && (localNameArray[0].equals(ER7Reader.MESSAGE_ROOT_ID))) {
        return;
    } else if (localNameArray.length == 2) {
        if (isHeaderSegment(localNameArray[0])) {
            if ((localNameArray[1].length() == 1) && (localNameArray[1].charAt(0) == '1')) {
                fieldSeparator = String.valueOf(output.charAt(output.length() - 1));
                return;
            } else if ((localNameArray[1].length() == 1) && (localNameArray[1].charAt(0) == '2')) {
                CharSequence separators = output.subSequence(output.length() - 4, output.length());
                componentSeparator = String.valueOf(separators.charAt(0));
                repetitionSeparator = String.valueOf(separators.charAt(1));
                escapeCharacter = String.valueOf(separators.charAt(2));
                subcomponentSeparator = String.valueOf(separators.charAt(3));
            }
        }
    }

    int currentDelimeterCount = localNameArray.length - 1;

    /*
     * We don't want to have tailing separators, so once we get to the last
     * element of a nested level, we delete the last character.
     */
    if (currentDelimeterCount > previousDelimeterCount) {
        previousDelimeterCount = currentDelimeterCount;
    } else if (currentDelimeterCount < previousDelimeterCount) {
        output.deleteCharAt(output.length() - 1);
        previousDelimeterCount = currentDelimeterCount;
    }

    /*
     * The number of periods in the element tells us the level. So, MSH is
     * at level 0, MSH.3 is at level 1, MSH.3.1 at level 2, and so on. We
     * can use this to determine which seperator to append once the element
     * is closed.
     * 
     * MIRTH-2078: Only add the last character if the root delimiter is 0
     * (HL7Message) or the current element level is deeper than the root
     * level. This only pertains to partial XML messages where the root is a
     * field or component.
     */
    if (rootLevel == 0 || currentDelimeterCount >= rootLevel) {
        switch (currentDelimeterCount) {
        case 0:
            output.append(segmentSeparator);
            break;
        case 1:
            output.append(fieldSeparator);
            break;
        case 2:
            output.append(componentSeparator);
            break;
        case 3:
            output.append(subcomponentSeparator);
            break;
        default:
            break;
        }
    }
}

From source file:netbeanstypescript.TSStructureScanner.java

@Override
public Map<String, List<OffsetRange>> folds(ParserResult pr) {
    Object arr = TSService.call("getFolds", pr.getSnapshot().getSource().getFileObject());
    if (arr == null) {
        return Collections.emptyMap();
    }/* w  w w.j  a v  a  2s. com*/
    List<OffsetRange> ranges = new ArrayList<>();
    CharSequence text = pr.getSnapshot().getText();
    for (JSONObject span : (List<JSONObject>) arr) {
        int start = ((Number) span.get("start")).intValue();
        int end = ((Number) span.get("end")).intValue();
        if (text.charAt(start) == '/') {
            // ts.OutliningElementsCollector creates folds for sequences of multiple //-comments
            // preceding a declaration, but this can prevent NetBeans's <editor-fold> directives
            // from working. Remove all lines up to and including the last such directive.
            int startDelta = 0;
            for (Matcher m = editorFolds.matcher(text.subSequence(start, end)); m.find();) {
                startDelta = m.end();
            }
            start += startDelta;
            // There may be only a single line left - for consistency, don't fold it
            if (text.subSequence(start, end).toString().indexOf('\n') < 0) {
                continue;
            }
        }
        ranges.add(new OffsetRange(start, end));
    }
    return Collections.singletonMap("codeblocks", ranges);
}

From source file:org.greencheek.utils.environment.propertyplaceholder.resolver.value.VariablePlaceholderValueResolver.java

/**
 * Taken from Spring StringUtils (org.springframework.util.StringUtils;)
 *
 * Test whether the given string matches the given substring
 * at the given index.//from  w  w  w.  j a  v  a 2  s .co m
 * @param str the original string (or StringBuilder)
 * @param index the index in the original string to start matching against
 * @param substring the substring to match at the given index
 */
public boolean substringMatch(CharSequence str, int index, CharSequence substring) {
    for (int j = 0; j < substring.length(); j++) {
        int i = index + j;
        if (i >= str.length() || str.charAt(i) != substring.charAt(j)) {
            return false;
        }
    }
    return true;
}

From source file:dk.teachus.backend.test.CreateMysqlTestDatabase.java

private List<String> parseSqlIntoSingleStatements(CharSequence sql) {
    List<String> statements = new ArrayList<String>();

    StringBuilder statement = new StringBuilder();
    boolean escape = false;
    boolean quote = false;
    for (int n = 0; n < sql.length(); n++) {
        char currentChar = sql.charAt(n);

        switch (currentChar) {
        case '"':
        case '`':
        case '\'':
            if (escape == false) {
                quote = quote == false;//from   w ww. j  a  v  a 2s.c  o m
            }
            escape = false;
            statement.append(currentChar);
            break;
        case '\\':
            escape = escape == false;
            statement.append(currentChar);
            break;
        case ';':
            if (quote == false) {
                statements.add(statement.toString());
                statement = new StringBuilder();
            }
            break;
        default:
            statement.append(currentChar);
        }
    }

    String sqlStatement = statement.toString();
    sqlStatement = sqlStatement.trim();

    if (sqlStatement.length() > 0) {
        statements.add(sqlStatement);
    }

    return statements;
}