I've got the C code to do it, and it's not that complicated, but I
thought I'd ask as a new guy if there's a package or set of functions
written to do such a thing.
I'm thinking of just doing a Split on the , and then generating the
string from first '-' list, but at the same time ... if there's a
handy thing to do this, I'm lazy.
It's a long user-oriented story as to why this is not being done with regexp's.
ron
Yep, that's pretty much what I did.
I used the nice Trim function to clean up the string and also I
covered people making typos like two commas in a row etc. It's easier
to cover silly user typos than to sit on the phone arguing with people
about whether you should cover silly user typos :-)
What's fun is it took no time at all to do this thing that is just not
that fun in C :-)
ron
Many of your conversions are not necessary. The program below
is still valid Go. The only required conversions here are the ones
that make the right operand of a shift unsigned. The compiler does
*not* know exactly what to expect for that case: did you mean
x<<-1 or x<<4294967295? Go forces you to make the operand
unsigned to avoid the ambiguity.
Russ
package main
import (
"fmt"
"strings"
"strconv"
)
const (
BitOfWord = 32
Shift = 5
Mask = 0x1F
)
type Set []uint32
func (x *Set) SetInt(i int, set bool) {
y := *x
l := i>>Shift + 1
if l > cap(y) {
println("new set", i)
x0 := make(Set, l)
copy(x0, y)
*x = x0
y = *x
}
if set {
y[i>>Shift] |= 1 << (uint(i) & Mask)
} else {
y[i>>Shift] &^= 1 << (uint(i) & Mask)
}
}
if x0&(1<<uint(j)) != 0 {
f(i<<Shift + j)
the uint32() of right shift is *exactly* the one I wish could be
removed.
From Spec: "The right operand in a shift operation must have unsigned
integer type or be an untyped constant that can be converted to
unsigned integer type."
So when i = -1 and <<unit32(i) does not help compiler to detect the
bug, does it?
On 8月31日, 下午7时53分, Russ Cox <r...@golang.org> wrote:
no but it removes any doubt about whether it is a >>1.
the 32 is unnecessary: you can just say uint(i).
russ
Alternately Go could have a shift operator which determines direction automatically based upon the sign of the operand. That would be a little more natural when writing code that performs shifts at the expense of making the compiler work a little bit harder...
Ellie
Eleanor McHugh
Games With Brains
http://feyeleanor.tel
----
raise ArgumentError unless @reality.responds_to? :reason