< prev index next >

src/java.base/share/classes/java/lang/StringConcatHelper.java

Print this page


   1 /*
   2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 200      * @param coder coder to add with
 201      * @param value boolean value to encode
 202      * @return new index
 203      */
 204     static int prepend(int index, byte[] buf, byte coder, boolean value) {
 205         if (coder == String.LATIN1) {
 206             if (value) {
 207                 buf[--index] = 'e';
 208                 buf[--index] = 'u';
 209                 buf[--index] = 'r';
 210                 buf[--index] = 't';
 211             } else {
 212                 buf[--index] = 'e';
 213                 buf[--index] = 's';
 214                 buf[--index] = 'l';
 215                 buf[--index] = 'a';
 216                 buf[--index] = 'f';
 217             }
 218         } else {
 219             if (value) {
 220                 StringUTF16.putChar(buf, --index, 'e');
 221                 StringUTF16.putChar(buf, --index, 'u');
 222                 StringUTF16.putChar(buf, --index, 'r');
 223                 StringUTF16.putChar(buf, --index, 't');
 224             } else {
 225                 StringUTF16.putChar(buf, --index, 'e');
 226                 StringUTF16.putChar(buf, --index, 's');
 227                 StringUTF16.putChar(buf, --index, 'l');
 228                 StringUTF16.putChar(buf, --index, 'a');
 229                 StringUTF16.putChar(buf, --index, 'f');
 230             }
 231         }
 232         return index;
 233     }
 234 
 235     /**
 236      * Prepends the stringly representation of byte value into buffer,
 237      * given the coder and final index. Index is measured in chars, not in bytes!
 238      *
 239      * @param index final char index in the buffer
 240      * @param buf   buffer to append to
 241      * @param coder coder to add with
 242      * @param value byte value to encode
 243      * @return new index
 244      */
 245     static int prepend(int index, byte[] buf, byte coder, byte value) {
 246         return prepend(index, buf, coder, (int)value);
 247     }
 248 
 249     /**
 250      * Prepends the stringly representation of char value into buffer,
 251      * given the coder and final index. Index is measured in chars, not in bytes!
 252      *
 253      * @param index final char index in the buffer
 254      * @param buf   buffer to append to
 255      * @param coder coder to add with
 256      * @param value char value to encode
 257      * @return new index
 258      */
 259     static int prepend(int index, byte[] buf, byte coder, char value) {
 260         if (coder == String.LATIN1) {
 261             buf[--index] = (byte) (value & 0xFF);
 262         } else {
 263             StringUTF16.putChar(buf, --index, value);
 264         }
 265         return index;
 266     }
 267 
 268     /**
 269      * Prepends the stringly representation of short value into buffer,
 270      * given the coder and final index. Index is measured in chars, not in bytes!
 271      *
 272      * @param index final char index in the buffer
 273      * @param buf   buffer to append to
 274      * @param coder coder to add with
 275      * @param value short value to encode
 276      * @return new index
 277      */
 278     static int prepend(int index, byte[] buf, byte coder, short value) {
 279         return prepend(index, buf, coder, (int)value);
 280     }
 281 
 282     /**
 283      * Prepends the stringly representation of integer value into buffer,
 284      * given the coder and final index. Index is measured in chars, not in bytes!
 285      *
 286      * @param index final char index in the buffer
 287      * @param buf   buffer to append to
 288      * @param coder coder to add with
 289      * @param value integer value to encode
 290      * @return new index
 291      */
 292     static int prepend(int index, byte[] buf, byte coder, int value) {
 293         if (coder == String.LATIN1) {
 294             return Integer.getChars(value, index, buf);
 295         } else {
 296             return Integer.getCharsUTF16(value, index, buf);
 297         }
 298     }
 299 
 300     /**
 301      * Prepends the stringly representation of long value into buffer,
 302      * given the coder and final index. Index is measured in chars, not in bytes!
 303      *
 304      * @param index final char index in the buffer
 305      * @param buf   buffer to append to
 306      * @param coder coder to add with
 307      * @param value long value to encode
 308      * @return new index
 309      */
 310     static int prepend(int index, byte[] buf, byte coder, long value) {
 311         if (coder == String.LATIN1) {
 312             return Long.getChars(value, index, buf);
 313         } else {
 314             return Long.getCharsUTF16(value, index, buf);
 315         }
 316     }
 317 
 318     /**
 319      * Prepends the stringly representation of String value into buffer,
 320      * given the coder and final index. Index is measured in chars, not in bytes!
 321      *
 322      * @param index final char index in the buffer
 323      * @param buf   buffer to append to
 324      * @param coder coder to add with
 325      * @param value String value to encode
 326      * @return new index
 327      */
 328     static int prepend(int index, byte[] buf, byte coder, String value) {
 329         index -= value.length();
 330         value.getBytes(buf, index, coder);
 331         return index;
 332     }
 333 
 334     /**


   1 /*
   2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 200      * @param coder coder to add with
 201      * @param value boolean value to encode
 202      * @return new index
 203      */
 204     static int prepend(int index, byte[] buf, byte coder, boolean value) {
 205         if (coder == String.LATIN1) {
 206             if (value) {
 207                 buf[--index] = 'e';
 208                 buf[--index] = 'u';
 209                 buf[--index] = 'r';
 210                 buf[--index] = 't';
 211             } else {
 212                 buf[--index] = 'e';
 213                 buf[--index] = 's';
 214                 buf[--index] = 'l';
 215                 buf[--index] = 'a';
 216                 buf[--index] = 'f';
 217             }
 218         } else {
 219             if (value) {
 220                 StringUTF16.Trusted.putChar(buf, --index, 'e');
 221                 StringUTF16.Trusted.putChar(buf, --index, 'u');
 222                 StringUTF16.Trusted.putChar(buf, --index, 'r');
 223                 StringUTF16.Trusted.putChar(buf, --index, 't');
 224             } else {
 225                 StringUTF16.Trusted.putChar(buf, --index, 'e');
 226                 StringUTF16.Trusted.putChar(buf, --index, 's');
 227                 StringUTF16.Trusted.putChar(buf, --index, 'l');
 228                 StringUTF16.Trusted.putChar(buf, --index, 'a');
 229                 StringUTF16.Trusted.putChar(buf, --index, 'f');
 230             }
 231         }
 232         return index;
 233     }
 234 
 235     /**
 236      * Prepends the stringly representation of byte value into buffer,
 237      * given the coder and final index. Index is measured in chars, not in bytes!
 238      *
 239      * @param index final char index in the buffer
 240      * @param buf   buffer to append to
 241      * @param coder coder to add with
 242      * @param value byte value to encode
 243      * @return new index
 244      */
 245     static int prepend(int index, byte[] buf, byte coder, byte value) {
 246         return prepend(index, buf, coder, (int)value);
 247     }
 248 
 249     /**
 250      * Prepends the stringly representation of char value into buffer,
 251      * given the coder and final index. Index is measured in chars, not in bytes!
 252      *
 253      * @param index final char index in the buffer
 254      * @param buf   buffer to append to
 255      * @param coder coder to add with
 256      * @param value char value to encode
 257      * @return new index
 258      */
 259     static int prepend(int index, byte[] buf, byte coder, char value) {
 260         if (coder == String.LATIN1) {
 261             buf[--index] = (byte) (value & 0xFF);
 262         } else {
 263             StringUTF16.Trusted.putChar(buf, --index, value);
 264         }
 265         return index;
 266     }
 267 
 268     /**
 269      * Prepends the stringly representation of short value into buffer,
 270      * given the coder and final index. Index is measured in chars, not in bytes!
 271      *
 272      * @param index final char index in the buffer
 273      * @param buf   buffer to append to
 274      * @param coder coder to add with
 275      * @param value short value to encode
 276      * @return new index
 277      */
 278     static int prepend(int index, byte[] buf, byte coder, short value) {
 279         return prepend(index, buf, coder, (int)value);
 280     }
 281 
 282     /**
 283      * Prepends the stringly representation of integer value into buffer,
 284      * given the coder and final index. Index is measured in chars, not in bytes!
 285      *
 286      * @param index final char index in the buffer
 287      * @param buf   buffer to append to
 288      * @param coder coder to add with
 289      * @param value integer value to encode
 290      * @return new index
 291      */
 292     static int prepend(int index, byte[] buf, byte coder, int value) {
 293         if (coder == String.LATIN1) {
 294             return Integer.getChars(value, index, buf);
 295         } else {
 296             return StringUTF16.Trusted.getChars(value, index, buf);
 297         }
 298     }
 299 
 300     /**
 301      * Prepends the stringly representation of long value into buffer,
 302      * given the coder and final index. Index is measured in chars, not in bytes!
 303      *
 304      * @param index final char index in the buffer
 305      * @param buf   buffer to append to
 306      * @param coder coder to add with
 307      * @param value long value to encode
 308      * @return new index
 309      */
 310     static int prepend(int index, byte[] buf, byte coder, long value) {
 311         if (coder == String.LATIN1) {
 312             return Long.getChars(value, index, buf);
 313         } else {
 314             return StringUTF16.Trusted.getChars(value, index, buf);
 315         }
 316     }
 317 
 318     /**
 319      * Prepends the stringly representation of String value into buffer,
 320      * given the coder and final index. Index is measured in chars, not in bytes!
 321      *
 322      * @param index final char index in the buffer
 323      * @param buf   buffer to append to
 324      * @param coder coder to add with
 325      * @param value String value to encode
 326      * @return new index
 327      */
 328     static int prepend(int index, byte[] buf, byte coder, String value) {
 329         index -= value.length();
 330         value.getBytes(buf, index, coder);
 331         return index;
 332     }
 333 
 334     /**


< prev index next >