sortregular

package module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 2 Imported by: 0

README

SORT_REGULAR in Go

This repository contains a Go implementation of the SORT_REGULAR from PHP.

Usage

Import the package and use the sort_regular function:

package main

import (
	"github.com/demouth/sortregular-go"
)

func main() {
	strings := []string{
		"lemon",
		"apple",
		"0     ",
		" 1    ",
		"  2   ",
		"   3  ",
		"   04 ",
		"    05",
	}

	sortregular.SortRegular(strings)

	for _, s := range strings {
		println(s)
	}
}

PHP SORT_REGULAR

For reference, here's the original SORT_REGULAR in PHP:

<?php

$a = [
    'lemon',
    'apple',
    '0     ',
    ' 1    ',
    '  2   ',
    '   3  ',
    '   04 ',
    '    05',
];
sort($a);
var_dump($a);
/*
array(8) {
  [0]=>
  string(6) "0     "
  [1]=>
  string(6) " 1    "
  [2]=>
  string(6) "  2   "
  [3]=>
  string(6) "   3  "
  [4]=>
  string(6) "   04 "
  [5]=>
  string(6) "    05"
  [6]=>
  string(5) "apple"
  [7]=>
  string(5) "lemon"
}
*/

Documentation

Index

Constants

View Source
const (
	IS_LONG   = 1
	IS_DOUBLE = 2 // not supported

)

Variables

This section is empty.

Functions

func SortRegular

func SortRegular(strings []string)

func ZendSort added in v1.2.0

func ZendSort(base []string, cmp compareFunc, swp swapFunc)

https://github.com/php/php-src/blob/0a0e8064e044b133da423952d8e78d50c4841a2e/Zend/zend_sort.c#L248

func ZendiSmartStrcmp added in v1.2.0

func ZendiSmartStrcmp(s1, s2 string) int

if s1 is larger, return 1 if s2 is larger, return -1 https://github.com/php/php-src/blob/98b43d07f9d0bea021c8fd6bda70bfdbbb7a6b7f/Zend/zend_operators.c#L3323

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL