github.com/blend/go-sdk@v1.20240719.1/stringutil/indent.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package stringutil
     9  
    10  import "strings"
    11  
    12  // Indent applies an indent prefix to a given corpus except the first line.
    13  func Indent(indent, corpus string) string {
    14  	return strings.Join(IndentLines(indent, SplitLines(corpus)), "\n")
    15  }
    16  
    17  // IndentLines adds a prefix to a given list of strings except the first string.
    18  func IndentLines(indent string, corpus []string) []string {
    19  	for index := 1; index < len(corpus); index++ {
    20  		corpus[index] = indent + corpus[index]
    21  	}
    22  	return corpus
    23  }