Insert a codepoint into the buffer, automatically dealing with surrogate
pairs

@param aSeq
source sequence
@param nIndex
index
@param nCodepoint
codepoint to be inserted
323418
public static void insert (@Nonnull final CharSequence aSeq, final int nIndex, final int nCodepoint)
  {
    if (!(aSeq instanceof StringBuilder))
    {
      insert (new StringBuilder (aSeq), nIndex, nCodepoint);
    }
    else
    {
      int nI = nIndex;
      if (nI > 0 && nI < aSeq.length ())
      {
        final char ch = aSeq.charAt (nI);
        final boolean low = Character.isLowSurrogate (ch);
        if (low && Character.isHighSurrogate (aSeq.charAt (nI - 1)))
        {
          nI--;
        }
      }
      ((StringBuilder) aSeq).insert (nI, Character.toChars (nCodepoint));
    }
  }
567920
@Override
	public T visitAnySequence(AnySequenceContext ctx) {
//		on(ctx);
		appendAst(ctx, tok(SEQUENCE));
		return super.visitAnySequence(ctx);
	}
180894
public void insert(final AbstractInsnNode location,
            final AbstractInsnNode insn) {
        ++size;
        AbstractInsnNode next = location.next;
        if (next == null) {
            last = insn;
        } else {
            next.prev = insn;
        }
        location.next = insn;
        insn.next = next;
        insn.prev = location;
        cache = null;
        insn.index = 0; // insn now belongs to an InsnList
    }
417881
@Override
  final protected void addSinglePoint(int position, int additionalId,
      long additionalRef, Integer id, Long ref) {
    addRange(position, position, additionalId, additionalRef, id, ref);
  }
111651
public static void setChar (@Nonnull final CharSequence aSeq, final int nIndex, @Nonnull final Codepoint aCodepoint)
  {
    setChar (aSeq, nIndex, aCodepoint.getValue ());
  }
996359
@Override
    public StrBuilder append(final CharSequence seq) {
        if (seq == null) {
            return appendNull();
        }
        return append(seq.toString());
    }
632220
public void addNewKernelPoint()
    {
        KernelPoint source = points.get(0);
        KernelPoint toAdd = new KernelPoint(k, errorTolerance);
        toAdd.setMaxBudget(maxBudget);
        toAdd.setBudgetStrategy(budgetStrategy);
        
        standardMove(toAdd, source);
        toAdd.kernelAccel = source.kernelAccel;
        toAdd.vecs = source.vecs;
        toAdd.alpha = new DoubleList(source.alpha.size());
        for (int i = 0; i < source.alpha.size(); i++)
            toAdd.alpha.add(0.0);
        points.add(toAdd);
    }
9262
@Override
    public final int get(int codePoint) {
        int value;
        int ix;
        
        if (codePoint >= 0) {
            if (codePoint < 0x0d800 || (codePoint > 0x0dbff && codePoint <= 0x0ffff)) {
                // Ordinary BMP code point, excluding leading surrogates.
                // BMP uses a single level lookup.  BMP index starts at offset 0 in the Trie2 index.
                // 32 bit data is stored in the index array itself.
                ix = index[codePoint >> UTRIE2_SHIFT_2];
                ix = (ix << UTRIE2_INDEX_SHIFT) + (codePoint & UTRIE2_DATA_MASK);
                value = data32[ix];
                return value;
            } 
            if (codePoint <= 0xffff) {
                // Lead Surrogate Code Point.  A Separate index section is stored for
                // lead surrogate code units and code points.
                //   The main index has the code unit data.
                //   For this function, we need the code point data.
                // Note: this expression could be refactored for slightly improved efficiency, but
                //       surrogate code points will be so rare in practice that it's not worth it.
                ix = index[UTRIE2_LSCP_INDEX_2_OFFSET + ((codePoint - 0xd800) >> UTRIE2_SHIFT_2)];
                ix = (ix << UTRIE2_INDEX_SHIFT) + (codePoint & UTRIE2_DATA_MASK);
                value = data32[ix];
                return value;
            }
            if (codePoint < highStart) {
                // Supplemental code point, use two-level lookup.
                ix = (UTRIE2_INDEX_1_OFFSET - UTRIE2_OMITTED_BMP_INDEX_1_LENGTH) + (codePoint >> UTRIE2_SHIFT_1);
                ix = index[ix];
                ix += (codePoint >> UTRIE2_SHIFT_2) & UTRIE2_INDEX_2_MASK;
                ix = index[ix];
                ix = (ix << UTRIE2_INDEX_SHIFT) + (codePoint & UTRIE2_DATA_MASK);
                value = data32[ix];
                return value;
            }
            if (codePoint <= 0x10ffff) {
                value = data32[highValueIndex];
                return value;
            }
        }
        
        // Fall through.  The code point is outside of the legal range of 0..0x10ffff.
        return errorValue;
    }
680219
@Override
    public int[] toIdList(int codePoint)
    {
        int count;
        if (codePoint < 0x80)
            count = 1;
        else if (codePoint < 0x800)
            count = 2;
        else if (codePoint < 0x10000)
            count = 3;
        else if (codePoint < 0x200000)
            count = 4;
        else if (codePoint < 0x4000000)
            count = 5;
        else if (codePoint <= 0x7fffffff)
            count = 6;
        else
            return EMPTYLIST;
        int[] r = new int[count];
        switch (count)
        { /* note: code falls through cases! */
            case 6:
                r[5] = (char) (0x80 | (codePoint & 0x3f));
                codePoint = codePoint >> 6;
                codePoint |= 0x4000000;
            case 5:
                r[4] = (char) (0x80 | (codePoint & 0x3f));
                codePoint = codePoint >> 6;
                codePoint |= 0x200000;
            case 4:
                r[3] = (char) (0x80 | (codePoint & 0x3f));
                codePoint = codePoint >> 6;
                codePoint |= 0x10000;
            case 3:
                r[2] = (char) (0x80 | (codePoint & 0x3f));
                codePoint = codePoint >> 6;
                codePoint |= 0x800;
            case 2:
                r[1] = (char) (0x80 | (codePoint & 0x3f));
                codePoint = codePoint >> 6;
                codePoint |= 0xc0;
            case 1:
                r[0] = (char) codePoint;
        }
        return r;
    }
1199952
static int codePointAtImpl(char[] a, int index, int limit) {
        char c1 = a[index];
        if (isHighSurrogate(c1) && ++index < limit) {
            char c2 = a[index];
            if (isLowSurrogate(c2)) {
                return toCodePoint(c1, c2);
            }
        }
        return c1;
    }
483575
public void ifeq(String target) throws IOException
    {
        if (wideIndex)
        {
            out.writeByte(NOT_IFEQ);
            out.writeShort(WIDEFIXOFFSET);
            Branch branch = createBranch(target);
            out.writeByte(GOTO_W);
            out.writeInt(branch);
        }
        else
        {
            Branch branch = createBranch(target);
            out.writeOpCode(IFEQ);
            out.writeShort(branch);
        }
    }
1360433
public static void reverseForEachCodePoint(String string, CodePointProcedure procedure)
    {
        for (int i = StringIterate.lastIndex(string); i >= 0; )
        {
            int codePoint = string.codePointAt(i);
            procedure.value(codePoint);
            if (i == 0)
            {
                i--;
            }
            else
            {
                i -= StringIterate.numberOfChars(string, i);
            }
        }
    }
1357562
@Benchmark void codePointBeforeNoSurrogates(int reps) {
    final int length = Math.min(this.length, MIN_SURROGATE);
    StringBuilder sb = new StringBuilder();
    for (int j = 0; j < length; j++) {
      sb.appendCodePoint(j);
    }
    for (int i = 0; i < reps; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 1; k < length; k++) {
          if (sb.codePointBefore(k) > MIN_SURROGATE)
            throw new Error();
        }
      }
    }
  }
1109397
public void setDevEndpoints(java.util.Collection<DevEndpoint> devEndpoints) {
        if (devEndpoints == null) {
            this.devEndpoints = null;
            return;
        }

        this.devEndpoints = new java.util.ArrayList<DevEndpoint>(devEndpoints);
    }
1166191
@Override
	public AbstractSequence<NucleotideCompound> getSequence(String sequence, long index ) throws CompoundNotFoundException, IOException {
		SequenceFileProxyLoader<NucleotideCompound> sequenceFileProxyLoader = new SequenceFileProxyLoader<NucleotideCompound>(
				file,
				sequenceParser,
				index,
				sequence.length(),
				compoundSet);
		return new RNASequence(sequenceFileProxyLoader, compoundSet);
	}
1044500
public void insertPointAfter( PolygonPoint a, PolygonPoint newPoint )
    {
        // Validate that 
        int index = _points.indexOf( a );
        if( index != -1 )
        {
            newPoint.setNext( a.getNext() );
            newPoint.setPrevious( a );
            a.getNext().setPrevious( newPoint );
            a.setNext( newPoint );
            _points.add( index+1, newPoint );
        }
        else
        {
            throw new RuntimeException( "Tried to insert a point into a Polygon after a point not belonging to the Polygon" );
        }
    }
336024
private static IfNode createCspInjection(
      SourceLocation insertionLocation, IdGenerator nodeIdGen, TemplateParam defn) {
    IfNode ifNode = new IfNode(nodeIdGen.genId(), insertionLocation);
    IfCondNode ifCondNode =
        new IfCondNode(
            nodeIdGen.genId(), insertionLocation, "if", referenceCspNonce(insertionLocation, defn));
    ifNode.addChild(ifCondNode);
    HtmlAttributeNode nonceAttribute =
        new HtmlAttributeNode(
            nodeIdGen.genId(), insertionLocation, insertionLocation.getBeginPoint());
    ifCondNode.addChild(nonceAttribute);
    nonceAttribute.addChild(new RawTextNode(nodeIdGen.genId(), "nonce", insertionLocation));
    HtmlAttributeValueNode attributeValue =
        new HtmlAttributeValueNode(
            nodeIdGen.genId(), insertionLocation, HtmlAttributeValueNode.Quotes.DOUBLE);
    nonceAttribute.addChild(attributeValue);
    // NOTE: we do not need to insert any print directives here, unlike the old implementation since
    // we are running before the autoescaper, so the escaper should insert whatever print directives
    // are appropriate.
    PrintNode printNode =
        new PrintNode(
            nodeIdGen.genId(),
            insertionLocation,
            /* isImplicit= */ true, // Implicit.  {$csp_nonce} not {print $csp_nonce}
            referenceCspNonce(insertionLocation, defn),
            /* attributes= */ ImmutableList.of(),
            ErrorReporter.exploding());
    attributeValue.addChild(printNode);
    return ifNode;
  }