package sourcemap

import (
	
)

type Mapping struct {
	GeneratedLine   int32 // 0-based
	GeneratedColumn int32 // 0-based count of UTF-16 code units

	SourceIndex    int32 // 0-based
	OriginalLine   int32 // 0-based
	OriginalColumn int32 // 0-based count of UTF-16 code units
}

type SourceMap struct {
	Sources        []string
	SourcesContent []SourceContent
	Mappings       []Mapping
}

This stores both the unquoted and the quoted values. We try to use the already-quoted value if possible so we don't need to re-quote it unnecessarily for maximum performance.
But sometimes we need to re-quote the value, such as when it contains non-ASCII characters and we are in ASCII-only mode. In that case we quote this parsed UTF-16 value.
	Value []uint16
}

func ( *SourceMap) ( int32,  int32) *Mapping {
	 := .Mappings
Binary search
	 := len()
	 := 0
	for  > 0 {
		 :=  / 2
		 :=  + 
		 := []
		if .GeneratedLine <  || (.GeneratedLine ==  && .GeneratedColumn <= ) {
			 =  + 1
			 -=  + 1
		} else {
			 = 
		}
	}
Handle search failure
	if  > 0 {
		 := &[-1]
Match the behavior of the popular "source-map" library from Mozilla
		if .GeneratedLine ==  {
			return 
		}
	}
	return nil
}

var base64 = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
A single base 64 digit can contain 6 bits of data. For the base 64 variable length quantities we use in the source map spec, the first bit is the sign, the next four bits are the actual value, and the 6th bit is the continuation bit. The continuation bit tells us whether there are more digits in this value following this digit. Continuation | Sign | | V V 101011
func ( int) []byte {
	var  int
	if  < 0 {
		 = ((-) << 1) | 1
	} else {
		 =  << 1
	}
Handle the common case up front without allocations
	if ( >> 5) == 0 {
		 :=  & 31
		return base64[ : +1]
	}

	 := []byte{}
	for {
		 :=  & 31
		 >>= 5
If there are still more digits in this value, we must make sure the continuation bit is marked
		if  != 0 {
			 |= 32
		}

		 = append(, base64[])

		if  == 0 {
			break
		}
	}

	return 
}

func ( []byte,  int) (int, int) {
	 := 0
	 := 0
Scan over the input
	for {
		 := bytes.IndexByte(base64, [])
		if  < 0 {
			break
		}
Decode a single byte
		 |= ( & 31) << 
		++
		 += 5
Stop if there's no continuation bit
		if ( & 32) == 0 {
			break
		}
	}
Recover the value
	 :=  >> 1
	if ( & 1) != 0 {
		 = -
	}
	return , 
}

func ( []uint16) (int, int, bool) {
	 := len()
	if  == 0 {
		return 0, 0, false
	}
Scan over the input
	 := 0
	 := 0
	 := 0
	for {
		if  >=  {
			return 0, 0, false
		}
		 := bytes.IndexByte(base64, byte([]))
		if  < 0 {
			return 0, 0, false
		}
Decode a single byte
		 |= ( & 31) << 
		++
		 += 5
Stop if there's no continuation bit
		if ( & 32) == 0 {
			break
		}
	}
Recover the value
	var  =  >> 1
	if ( & 1) != 0 {
		 = -
	}
	return , , true