Example usage for java.lang String getChars

List of usage examples for java.lang String getChars

Introduction

In this page you can find the example usage for java.lang String getChars.

Prototype

public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) 

Source Link

Document

Copies characters from this string into the destination character array.

Usage

From source file:org.openstreetmap.josm.tools.Utils.java

private static char[] stripChars(final String skipChars) {
    if (skipChars == null || skipChars.isEmpty()) {
        return DEFAULT_STRIP;
    }/*from   w w  w  .  j  av a2s.c  o m*/

    char[] chars = new char[DEFAULT_STRIP.length + skipChars.length()];
    System.arraycopy(DEFAULT_STRIP, 0, chars, 0, DEFAULT_STRIP.length);
    skipChars.getChars(0, skipChars.length(), chars, DEFAULT_STRIP.length);

    return chars;
}

From source file:ArabicReshaper.java

/**
 * Main Reshaping Function, With LamAlef Support
 * @param unshapedWord The UnReshaped Word
 * @return The Shaped Word with Lam Alef Support
 *//*from w  w w.j av a  2 s  . co  m*/
public String reshapeItWithLamAlef(String unshapedWord) {

    //The reshaped Word to Return
    StringBuffer reshapedWord = new StringBuffer("");

    //The Word length
    int wordLength = unshapedWord.length();

    //The Word Letters
    char[] wordLetters = new char[wordLength];

    //The reshaped Letters
    char[] reshapedLetters = new char[wordLength];

    //Indicator Character, to Tell that lam is exist
    char lamIndicator = 43;//The '+' 

    //Copy the unreshapedWord to the WordLetters Character Array
    unshapedWord.getChars(0, wordLength, wordLetters, 0);

    //Check if the Word Length is 0, then return empty String
    if (wordLength == 0) {
        return "";
    }

    //Check if the Word length is 1, then return the Reshaped One letter, which is the same character of input
    if (wordLength == 1) {
        return getReshapedGlphy(wordLetters[0], 1) + "";
    }

    //Check if the word length is 2, Check if the Word is LamAlef 
    if (wordLength == 2) {
        //Assign Candidate Lam
        char lam = wordLetters[0];

        //Assign Candidate Alef
        char alef = wordLetters[1];

        //Check if The word is Lam Alef.
        if (getLamAlef(alef, lam, true) > 0) {
            return (char) getLamAlef(alef, lam, true) + " ";
        }

    }

    //For the First Letter
    reshapedLetters[0] = getReshapedGlphy(wordLetters[0], 2);

    //The current Letter
    char currentLetter = wordLetters[0];

    /**
     * The Main Iterator
     */

    //Iterate over the word from the second character till the second to the last
    for (int i = 1; i < wordLength - 1; i++) {

        //Check if the Letters are Lam Alef
        if (getLamAlef(wordLetters[i], currentLetter, true) > 0) {
            //Check if the Letter before the Lam is 2 Forms Letter, to Make the Lam Alef as its the end of the Word
            if ((i - 2 < 0) || ((i - 2 >= 0) && (getGlphyType(wordLetters[i - 2]) == 2))) {

                //Mark the letter of Lam as Lam Indicator
                reshapedLetters[i - 1] = lamIndicator;

                //Assign Lam Alef to the Letter of Alef
                reshapedLetters[i] = (char) getLamAlef(wordLetters[i], currentLetter, true);

            } else { //The Letter before the Lam is more than 2 Forms Letter

                //Mark the letter of Lam as Lam Indicator
                reshapedLetters[i - 1] = lamIndicator;

                //Assign Lam Alef to the Letter of Alef
                reshapedLetters[i] = (char) getLamAlef(wordLetters[i], currentLetter, false);
            }
        } else { //The Word doesn't have LamAlef

            int beforeLast = i - 1;

            //Check if the Letter Before Last has only 2 Forms, for the current Letter to be as a start for a new Word!
            if (getGlphyType(wordLetters[beforeLast]) == 2) {

                //If the letter has only 2 shapes, then it doesnt matter which position it is, It'll be always the second form
                reshapedLetters[i] = getReshapedGlphy(wordLetters[i], 2);
            } else {

                //Then it should be in the middle which should be placed in its right form [3]
                reshapedLetters[i] = getReshapedGlphy(wordLetters[i], 3);
            }
        }
        //Assign the CurrentLetter as the Word Letter
        currentLetter = wordLetters[i];
    }

    /**
     * The Last Letters Check
     */

    //Check if the Letters are Lam Alef
    if (getLamAlef(wordLetters[wordLength - 1], wordLetters[wordLength - 2], true) > 0) {

        //Check if the Letter before the Lam is 2 Forms Letter, to Make the Lam Alef as its the end of the Word
        if (getGlphyType(wordLetters[wordLength - 3]) == 2) { //check for the last letter

            //Mark the letter of Lam as Lam Indicator
            reshapedLetters[wordLength - 2] = lamIndicator;

            //Assign Lam Alef to the Letter of Alef
            reshapedLetters[wordLength - 1] = (char) getLamAlef(wordLetters[wordLength - 1],
                    wordLetters[wordLength - 2], true);
        } else {

            //Mark the letter of Lam as Lam Indicator
            reshapedLetters[wordLength - 2] = lamIndicator;

            //Assign Lam Alef to the Letter of Alef
            reshapedLetters[wordLength - 1] = (char) getLamAlef(wordLetters[wordLength - 1],
                    wordLetters[wordLength - 2], false);
        }

    } else {
        //check for the last letter Before last has 2 forms, that means that the last Letter will be alone.
        if (getGlphyType(wordLetters[wordLength - 2]) == 2) {
            //If the letter has only 2 shapes, then it doesn't matter which position it is, It'll be always the second form
            reshapedLetters[wordLength - 1] = getReshapedGlphy(wordLetters[wordLength - 1], 1);
        } else {
            //Put the right form of the character, 4 for the last letter in the word
            reshapedLetters[wordLength - 1] = getReshapedGlphy(wordLetters[wordLength - 1], 4);
        }
    }

    /**
     * Assign the Final Results of Shaped Word
     */

    //Iterate over the Reshaped Letters and remove the Lam Indicators
    for (int i = 0; i < reshapedLetters.length; i++) {

        //Check if the Letter is Lam Indicator
        if (reshapedLetters[i] != lamIndicator)
            reshapedWord.append(reshapedLetters[i]);
    }

    //Return the Reshaped Word
    return reshapedWord.toString();
}

From source file:com.siviton.huanapi.data.HuanApi.java

private String getdevmac() {
    String address = getWireMacAddress();
    char[] buffer = new char[address.length()];
    address.getChars(0, address.length(), buffer, 0);
    String strMac = "" + buffer[0] + buffer[1] + buffer[3] + buffer[4] + buffer[6] + buffer[7] + buffer[9]
            + buffer[10] + buffer[12] + buffer[13] + buffer[15] + buffer[16];
    return address;
}

From source file:com.bazaarvoice.jackson.rison.RisonGenerator.java

private void _writeRawLong(String text) throws IOException, JsonGenerationException {
    int room = _outputEnd - _outputTail;
    // If not, need to do it by looping
    text.getChars(0, room, _outputBuffer, _outputTail);
    _outputTail += room;/*w  w w . j ava2s  . c o m*/
    _flushBuffer();
    int offset = room;
    int len = text.length() - room;

    while (len > _outputEnd) {
        int amount = _outputEnd;
        text.getChars(offset, offset + amount, _outputBuffer, 0);
        _outputHead = 0;
        _outputTail = amount;
        _flushBuffer();
        offset += amount;
        len -= amount;
    }
    // And last piece (at most length of buffer)
    text.getChars(offset, offset + len, _outputBuffer, 0);
    _outputHead = 0;
    _outputTail = len;
}

From source file:com.aselalee.trainschedule.GetResultsFromSiteV2.java

private String formatFrequency(String frequency) {
    String result = frequency;/*from   ww w .jav a 2 s.  co m*/
    if (frequency.contains(" Except Holidays)")) {
        result = frequency.replace(" Except Holidays)", "\n(Except Holidays)");
        return result;
    }
    int freqLength = frequency.length();
    if (freqLength > 12) {
        int firstSpace = -1;
        int secondSpace = -1;
        firstSpace = frequency.indexOf(" ");
        if (firstSpace > 0) {
            secondSpace = frequency.indexOf(" ", firstSpace + 1);
        }
        if (secondSpace > 0) {
            char[] charArray = new char[freqLength];
            frequency.getChars(0, freqLength, charArray, 0);
            charArray[secondSpace] = '\n';
            result = null;
            result = new String(charArray);
        }
    }
    return result;
}

From source file:org.getobjects.foundation.kvc.KVCWrapper.java

/**
 *  Finds an accessor for the given property name.  Returns the
 *  accessor if the class has the named property, or null
 *  otherwise./*from   w  w w.  j a  v  a2 s .  co  m*/
 *
 *  @param _key the <em>simple</em> property name of the property to
 *  get.
 *
 **/
public IPropertyAccessor getAccessor(final Object _self, final String _key) {
    synchronized (this) {
        if (this.accessors == null)
            buildPropertyAccessors();
    }

    // hh: before this was iterating an array over names, hardcoded that for
    //     speed (no array creation, no String ops for exact matches)
    // this.accessors is a concurrent hashmap, hence no synchronized necessary
    IPropertyAccessor accessor;

    /* first check exact match, eg 'item' */

    if ((accessor = this.accessors.get(_key)) != null)
        return accessor;

    /* next check 'getItem' */

    final int len = _key.length();
    final char[] chars = new char[3 /* get */ + len];
    chars[0] = 'g';
    chars[1] = 'e';
    chars[2] = 't';

    _key.getChars(0, len, chars, 3 /* skip 'get' */);
    final char c0 = chars[3];
    if (c0 > 96 && c0 < 123 /* lowercase ASCII range */)
        chars[3] = (char) (c0 - 32); /* make uppercase */

    String s = new String(chars);
    if ((accessor = this.accessors.get(s)) != null)
        return accessor;

    /* finally with leading underscore */

    chars[3] = c0; /* restore lowercase char */
    chars[2] = '_';
    s = new String(chars, 2, len + 1);
    return this.accessors.get(s);
}

From source file:Snippet178.java

static void hookApplicationMenu(Display display, final String aboutName) {
    // Callback target
    Object target = new Object() {
        int commandProc(int nextHandler, int theEvent, int userData) {
            if (OS.GetEventKind(theEvent) == OS.kEventProcessCommand) {
                HICommand command = new HICommand();
                OS.GetEventParameter(theEvent, OS.kEventParamDirectObject, OS.typeHICommand, null,
                        HICommand.sizeof, null, command);
                switch (command.commandID) {
                case kHICommandPreferences:
                    return handleCommand("Preferences"); //$NON-NLS-1$
                case kHICommandAbout:
                    return handleCommand(aboutName);
                default:
                    break;
                }/*from w  w  w  .j av a  2s. com*/
            }
            return OS.eventNotHandledErr;
        }

        int handleCommand(String command) {
            Shell shell = new Shell();
            MessageBox preferences = new MessageBox(shell, SWT.ICON_WARNING);
            preferences.setText(command);
            preferences.open();
            shell.dispose();
            return OS.noErr;
        }
    };

    final Callback commandCallback = new Callback(target, "commandProc", 3); //$NON-NLS-1$
    int commandProc = commandCallback.getAddress();
    if (commandProc == 0) {
        commandCallback.dispose();
        return; // give up
    }

    // Install event handler for commands
    int[] mask = new int[] { OS.kEventClassCommand, OS.kEventProcessCommand };
    OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc, mask.length / 2, mask, 0, null);

    // create About ... menu command
    int[] outMenu = new int[1];
    short[] outIndex = new short[1];
    if (OS.GetIndMenuItemWithCommandID(0, kHICommandPreferences, 1, outMenu, outIndex) == OS.noErr
            && outMenu[0] != 0) {
        int menu = outMenu[0];

        int l = aboutName.length();
        char buffer[] = new char[l];
        aboutName.getChars(0, l, buffer, 0);
        int str = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault, buffer, l);
        OS.InsertMenuItemTextWithCFString(menu, str, (short) 0, 0, kHICommandAbout);
        OS.CFRelease(str);

        // add separator between About & Preferences
        OS.InsertMenuItemTextWithCFString(menu, 0, (short) 1, OS.kMenuItemAttrSeparator, 0);

        // enable pref menu
        OS.EnableMenuCommand(menu, kHICommandPreferences);

        // disable services menu
        OS.DisableMenuCommand(menu, kHICommandServices);
    }

    // schedule disposal of callback object
    display.disposeExec(new Runnable() {
        public void run() {
            commandCallback.dispose();
        }
    });
}

From source file:org.nuxeo.dam.object.relations.AssetRelationsBuilder.java

protected DocumentModel handleNonLicensedCompositionResource() {

    String tmp;
    int pos;//from www  . j av  a  2  s. c o  m

    initValues();

    // -------------------- Extract Info --------------------
    assetType = ASSET_TYPE.COMPOSITION_RESOURCE;

    tmp = titleNoExtension;
    pos = tmp.toLowerCase().lastIndexOf(" comp");
    if (pos > 0) {
        titleNoExtension = tmp.substring(0, pos);
    }

    tmp = titleNoExtension;
    pos = tmp.indexOf(" ");
    if (pos > 0) {
        name = tmp.substring(pos + 1);
        tmp = tmp.substring(0, pos);

        String seqNum = "";
        // First 1-n letters are the department
        char[] chars = new char[tmp.length()];
        tmp.getChars(0, tmp.length(), chars, 0);
        int i = 0;
        for (char c : chars) {
            if (Character.isDigit(c)) {
                seqNum = tmp.substring(i);
                break;
            } else {
                department += Character.toString(c);
            }
            i += 1;
        }

        SeqNumberExtractor sne = new SeqNumberExtractor(seqNum);
        seqNumberStr = sne.numberAsStr;
        seqNumberSuffix = sne.suffix;
    }

    // -------------------- Check --------------------
    // If we don't have enough information, we just do nothing
    if (StringUtils.isBlank(department) || StringUtils.isBlank(seqNumberStr) || StringUtils.isBlank(name)) {
        return doc;
    }

    // -------------------- Link to the StyleNumber --------------------
    checkDepartmentValueInDirectory(department);
    DocumentModel styleDoc;
    // A StyleNumber document has the "linking" and the "style_number" schemas (among others)
    String nxql = "SELECT * FROM StyleNumber WHERE style_number:department = '" + department + "'";
    nxql += " AND style_number:number = '" + seqNumberStr + "'";
    nxql += " AND style_number:short_name = '" + name + "'";
    nxql += USUAL_NXQL_LAST_FILTER;
    DocumentModelList docs = session.query(nxql);
    if (docs.size() == 0) {
        styleDoc = session.createDocumentModel(getStyleNumberContainerPath(), department + seqNumberStr + name,
                "StyleNumber");

        styleDoc.setPropertyValue("style_number:department", department);
        styleDoc.setPropertyValue("style_number:number", seqNumberStr);
        styleDoc.setPropertyValue("style_number:short_name", name);

        styleDoc = session.createDocument(styleDoc);
        styleDoc = session.saveDocument(styleDoc);

    } else {
        styleDoc = docs.get(0);
    }
    doc.setPropertyValue("linking:style_number_id", styleDoc.getId());

    // -------------------- Last Update(s) --------------------
    doc.setPropertyValue("asset:nature", VOC_COMPOSITION_RESOURCE);
    doc.setPropertyValue("asset:variation_letter", seqNumberSuffix);
    // doc.setPropertyValue("asset:licensing", VOC_LICENSED);

    // -------------------- Ok, we're done --------------------
    doc = session.saveDocument(doc);
    docModifiedAndSaved = true;
    return doc;
}

From source file:com.edgardleal.util.html.HTMLStringBuffer.java

/**
 * Append the raw object value of the given object to the buffer.
 * /* w w w. jav a 2 s  .c om*/
 * @param value
 *            the object value to append
 * @return a reference to this <tt>HTMLStringBuffer</tt> object
 */
public HTMLStringBuffer append(Object value) {
    String string = String.valueOf(value);
    int length = string.length();

    int newCount = count + length;
    if (newCount > characters.length) {
        expandCapacity(newCount);
    }
    string.getChars(0, length, characters, count);
    count = newCount;

    return this;
}

From source file:com.edgardleal.util.html.HTMLStringBuffer.java

/**
 * Append the raw string value of the given object to the buffer.
 * /*from   w ww .  j a  va 2s . c om*/
 * @param value
 *            the string value to append
 * @return a reference to this <tt>HTMLStringBuffer</tt> object
 */
public HTMLStringBuffer append(String value) {
    String string = (value != null) ? value : "null";
    int length = string.length();

    int newCount = count + length;
    if (newCount > characters.length) {
        expandCapacity(newCount);
    }
    string.getChars(0, length, characters, count);
    count = newCount;

    return this;
}