def ascii_to_hex(self, start, end): """Convert ascii to hex.""" num_bytes = 0 size = end - start ascii_range = self.view.extract_scope(start) # Determine if selection is within ascii range if start >= ascii_range.begin() and end <= ascii_range.end() + 1: # Single char selection or multi num_bytes = 1 if size == 0 else end - start if num_bytes != 0: row, column = self.view.rowcol(start) column = common.ascii_to_hex_col(start - ascii_range.begin(), self.group_size) hex_pos = self.view.text_point(row, column) start = hex_pos # Traverse row finding the specified bytes byte_count = num_bytes while byte_count: # Byte rising edge if self.view.score_selector(hex_pos, 'raw.nibble.upper'): hex_pos += 2 byte_count -= 1 # End of selection if byte_count == 0: end = hex_pos - 1 else: hex_pos += 1 return start, end, num_bytes
def hex_selection(self, start, num_bytes, first_pos): """Get hex selection.""" row, column = self.view.rowcol(first_pos) column = common.ascii_to_hex_col(start, self.group_size) hex_pos = self.view.text_point(row, column) # Log first byte if self.first_all == -1: self.first_all = hex_pos # Traverse row finding the specified bytes highlight_start = -1 byte_count = num_bytes while byte_count: # Byte rising edge if self.view.score_selector(hex_pos, 'raw.nibble.upper'): if highlight_start == -1: highlight_start = hex_pos hex_pos += 2 byte_count -= 1 # End of selection if byte_count == 0: self.selected_bytes.append(sublime.Region(highlight_start, hex_pos)) else: # Byte group falling edge self.selected_bytes.append(sublime.Region(highlight_start, hex_pos)) hex_pos += 1 highlight_start = -1 # Log address if num_bytes and not self.address_done: self.get_address(start + 2, num_bytes, row)
def hex_selection(self, start, num_bytes, first_pos): """Get hex selection.""" row, column = self.view.rowcol(first_pos) column = common.ascii_to_hex_col(start, self.group_size) hex_pos = self.view.text_point(row, column) # Log first byte if self.first_all == -1: self.first_all = hex_pos # Traverse row finding the specified bytes highlight_start = -1 byte_count = num_bytes while byte_count: # Byte rising edge if self.view.score_selector(hex_pos, 'raw.nibble.upper'): if highlight_start == -1: highlight_start = hex_pos hex_pos += 2 byte_count -= 1 # End of selection if byte_count == 0: self.selected_bytes.append( sublime.Region(highlight_start, hex_pos)) else: # Byte group falling edge self.selected_bytes.append( sublime.Region(highlight_start, hex_pos)) hex_pos += 1 highlight_start = -1 # Log address if num_bytes and not self.address_done: self.get_address(start + 2, num_bytes, row)