github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/mobile/primitives.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 12:09:43</date>
    10  //</624342654431268864>
    11  
    12  
    13  //包含用于基元类型的各种包装器。
    14  
    15  package geth
    16  
    17  import (
    18  	"errors"
    19  	"fmt"
    20  )
    21  
    22  //字符串表示str的s切片。
    23  type Strings struct{ strs []string }
    24  
    25  //SIZE返回切片中str的数目。
    26  func (s *Strings) Size() int {
    27  	return len(s.strs)
    28  }
    29  
    30  //get从切片返回给定索引处的字符串。
    31  func (s *Strings) Get(index int) (str string, _ error) {
    32  	if index < 0 || index >= len(s.strs) {
    33  		return "", errors.New("index out of bounds")
    34  	}
    35  	return s.strs[index], nil
    36  }
    37  
    38  //set在切片中的给定索引处设置字符串。
    39  func (s *Strings) Set(index int, str string) error {
    40  	if index < 0 || index >= len(s.strs) {
    41  		return errors.New("index out of bounds")
    42  	}
    43  	s.strs[index] = str
    44  	return nil
    45  }
    46  
    47  //字符串实现字符串接口。
    48  func (s *Strings) String() string {
    49  	return fmt.Sprintf("%v", s.strs)
    50  }
    51