// Copyright 2014 Oleku Konko All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.

// This module is a Table Writer  API for the Go Programming Language.
// The protocols were written in pure Go and works on windows and unix systems

package tablewriter

import (
	
	
	

	
)

var ansi = regexp.MustCompile("\033\\[(?:[0-9]{1,3}(?:;[0-9]{1,3})*)?[m|K]")

func ( string) int {
	return runewidth.StringWidth(ansi.ReplaceAllLiteralString(, ""))
}

// Simple Condition for string
// Returns value based on condition
func ( bool, ,  string) string {
	if  {
		return 
	}
	return 
}

func isNumOrSpace( rune) bool {
	return ('0' <=  &&  <= '9') ||  == ' '
}

// Format Table Header
// Replace _ , . and spaces
func ( string) string {
	 := len()
	 := []rune()
	for ,  := range  {
		switch  {
		case '_':
			[] = ' '
		case '.':
			// ignore floating number 0.0
			if ( != 0 && !isNumOrSpace([-1])) || ( != len()-1 && !isNumOrSpace([+1])) {
				[] = ' '
			}
		}
	}
	 = string()
	 = strings.TrimSpace()
	if len() == 0 &&  > 0 {
		// Keep at least one character. This is important to preserve
		// empty lines in multi-line headers/footers.
		 = " "
	}
	return strings.ToUpper()
}

// Pad String
// Attempts to place string in the center
func (,  string,  int) string {
	 :=  - DisplayWidth()
	if  > 0 {
		 := int(math.Ceil(float64( / 2)))
		 :=  - 
		return strings.Repeat(string(), ) +  + strings.Repeat(string(), )
	}
	return 
}

// Pad String Right position
// This would place string at the left side of the screen
func (,  string,  int) string {
	 :=  - DisplayWidth()
	if  > 0 {
		return  + strings.Repeat(string(), )
	}
	return 
}

// Pad String Left position
// This would place string at the right side of the screen
func (,  string,  int) string {
	 :=  - DisplayWidth()
	if  > 0 {
		return strings.Repeat(string(), ) + 
	}
	return 
}