Store or calculate char_offsets, adding the offset of the doc end
11991
def _get_char_offsets(self, char_offsets):
        """"""
        if char_offsets:
            char_offsets = char_offsets
            char_offsets.append(len(self.text))
        else:
            char_offsets = np.zeros(len(self.tokens) + 1)
            for i, tok in enumerate(self.tokens):
                # Add 1 to account for the spaces between tokens
                char_offsets[i + 1] = char_offsets[i] + len(tok) + 1
            char_offsets[-1] = len(self.text)
        return np.array(char_offsets)
507834
private void appendToBuf(char[] ch, int start, int end) {
        if (start == end) {
            return;
        }
        int neededBufLen = pos + (end - start);
        if (neededBufLen > buf.length) {
            char[] newBuf = new char[neededBufLen];
            System.arraycopy(buf, 0, newBuf, 0, pos);
            if (bufHolder == null) {
                bufHolder = buf; // keep the original around
            }
            buf = newBuf;
        }
        System.arraycopy(ch, start, buf, pos, end - start);
        pos += (end - start);
    }
40007
function getOffset(reader, offSize) {
            var v = 0;
            for (var i = 0; i < offSize; i++) {
                v <<= 8;
                v += reader.readUint8();
            }
            return v;
        }
586582
def align(offset, alignment):
    
    if offset % alignment == 0:
        return offset
    return offset + (alignment - (offset % alignment))
1072781
def charindex(self, line, char, context):
        """"""
        #Make sure that we have chars and lines to work from
        if len(context.bufferstr) > 0 and len(self._chars) == 0:
            #Add one for the \n that we split on for each line
            self._chars = [ len(x) + 1 for x in context.bufferstr ]
            #Remove the last line break since it doesn't exist
            self._chars[-1] -= 1

            #Now we want to add up the number of characters in each line
            #as the lines progress so that it is easy to search for the
            #line of a single character index
            total = 0
            for i in range(len(self._chars)):
                total += self._chars[i]
                self._chars[i] = total
        
        return self._chars[line - 1] + char
701134
def get_string(self, offset=0):
        """"""
        if not self.has_space(offset=offset):
            return ''

        # Get a char for each char in the current string from pos onward
        #  solong as the char is not whitespace.
        string = self.string
        pos = self.pos + offset
        for i, char in enumerate(string[pos:]):
            if char.isspace():
                return string[pos:pos + i]
        else:
            return string[pos:]
600847
def get_character(self, position, offset=0):
        """"""
        position = self.get_position(position) + offset
        cursor = self.textCursor()
        cursor.movePosition(QTextCursor.End)
        if position < cursor.position():
            cursor.setPosition(position)
            cursor.movePosition(QTextCursor.Right,
                                QTextCursor.KeepAnchor)
            return to_text_string(cursor.selectedText())
        else:
            return ''
241563
private int writeShort(String value, int offset, int end)
    throws IOException
  {
    int ch;
  
    OutputStreamWithBuffer os = _os;
    byte []buffer = os.buffer();
    int bOffset = os.offset();
    
    end = Math.min(end, offset + buffer.length - bOffset);
  
    for (; offset < end && (ch = value.charAt(offset)) < 0x80; offset++) {
      buffer[bOffset++] = (byte) ch;
    }
    
    os.offset(bOffset);
    
    return offset;
  }
502791
function getNodeForCharacterOffset(root, offset) {
  var node = getLeafNode(root);
  var nodeStart = 0;
  var nodeEnd = 0;

  while (node) {
    if (node.nodeType === TEXT_NODE$3) {
      nodeEnd = nodeStart + node.textContent.length;

      if (nodeStart <= offset && nodeEnd >= offset) {
        return {
          node: node,
          offset: offset - nodeStart
        };
      }

      nodeStart = nodeEnd;
    }

    node = getLeafNode(getSiblingNode(node));
  }
}
290238
def match_any_char(self, chars, offset=0):
        """"""
        if not self.has_space(offset=offset):
            return ''
        current = self.string[self.pos + offset]
        return current if current in chars else ''
794431
public static void writeUnsignedShortLittleEndian(byte[] buffer, int offset, int value) {
		buffer[offset++] = (byte)(value & 0xFF);
		buffer[offset] = (byte)((value >> 8) & 0xFF);
	}
277998
protected static final void checkOffset(int offset, CharacterIterator text) {
        if (offset < text.getBeginIndex() || offset > text.getEndIndex()) {
            throw new IllegalArgumentException("offset out of bounds");
        }
    }
1361332
def apply_offset(self):
    ''''''
    self._ensure_modification_is_safe()

    if self.query.offset != 0:
      self._iterable = \
        offset_gen(self.query.offset, self._iterable, self._skipped_inc)
178750
def pack_word(self, offset, word):
        
        o = self._offset + offset
        return struct.pack_into("<H", self._buf, o, word)
134585
function base32DecodeLastCharacter(chunk, characterIndex, buffer, index) {
    const byteIndex = Math.floor(index + (characterIndex * 5) / 8);
    const offset = characterIndex % 8;
    switch (offset) {
        case 1:
            buffer[byteIndex] |= chunk >>> 2;
            break;
        case 3:
            buffer[byteIndex] |= chunk >>> 4;
            break;
        case 4:
            buffer[byteIndex] |= chunk >>> 1;
            break;
        case 6:
            buffer[byteIndex] |= chunk >>> 3;
            break;
        case 7:
            buffer[byteIndex] |= chunk;
            break;
    }
}
51005
private int offset(long index) {
    int offset = (int) (index % buffer.length);
    if (offset < 0) {
      offset += buffer.length;
    }
    return offset;
  }
909451
public void getChars(int start, int end, char[] dest, int destoff) {
        checkRange("getChars", start, end);

        if (end <= mGapStart) {
            System.arraycopy(mText, start, dest, destoff, end - start);
        } else if (start >= mGapStart) {
            System.arraycopy(mText, start + mGapLength, dest, destoff, end - start);
        } else {
            System.arraycopy(mText, start, dest, destoff, mGapStart - start);
            System.arraycopy(mText, mGapStart + mGapLength,
                    dest, destoff + (mGapStart - start),
                    end - mGapStart);
        }
    }