blob: f10385581da3a4390c161759e5f41f625d24ba12 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstra715ec202025-07-09 22:18:31 +02002 string copy_bits(string src, string dest
3 [, int srcstart [, int deststart [, int copylen ]]])
MG Mud User88f12472016-06-24 23:31:02 +02004
Zesstra715ec202025-07-09 22:18:31 +02005DESCRIPTION
6 Copy the bitrange [<srcstart>..<srcstart>+<copylen>[ from
7 bitstring <src> and copy it into the bitstring <dest> starting
8 at <deststart>, overwriting the original bits at those positions.
MG Mud User88f12472016-06-24 23:31:02 +02009
Zesstra715ec202025-07-09 22:18:31 +020010 The resulting combined string is returned, the input strings remain
11 unaffected.
MG Mud User88f12472016-06-24 23:31:02 +020012
Zesstra715ec202025-07-09 22:18:31 +020013 If <srcstart> is not given, <src> is copied from the start.
14 If <srcstart> is negative, it is counted from one past the last set
15 bit in the string (ie. '-1' will index the last set bit).
MG Mud User88f12472016-06-24 23:31:02 +020016
Zesstra715ec202025-07-09 22:18:31 +020017 If <deststart> is not given, <dest> will be overwritten from the start.
18 If <deststart> is negative, it is counted from one past the last set
19 bit in the string (ie. '-1' will index the last set bit).
MG Mud User88f12472016-06-24 23:31:02 +020020
Zesstra715ec202025-07-09 22:18:31 +020021 If <copylen> is not given, it is assumed to be infinite, ie. the result
22 will consist of <dest> up to position <deststart>, followed by
23 the data copied from <src>.
24 If <copylen> is negative, the function will copy the abs(<copylen>)
25 bits _before_ <srcstart> in to the result.
MG Mud User88f12472016-06-24 23:31:02 +020026
Zesstra715ec202025-07-09 22:18:31 +020027 None of the range limits can become negative.
MG Mud User88f12472016-06-24 23:31:02 +020028
Zesstra715ec202025-07-09 22:18:31 +020029EXAMPLES
30 copy_bits(src, dest, 10) === src[10..]
31 copy_bits(src, dest, 10, 5) === dest[0..4] + src[10..]
32 copy_bits(src, dest, 10, 5, 3)
33 === dest[0..4] + src[10..12] + dest[8..]
MG Mud User88f12472016-06-24 23:31:02 +020034
Zesstra715ec202025-07-09 22:18:31 +020035 (The src[]/dest[] is just for explanatory purposes!)
MG Mud User88f12472016-06-24 23:31:02 +020036
Zesstra715ec202025-07-09 22:18:31 +020037HISTORY
38 Introduced in LDMud 3.3.166.
MG Mud User88f12472016-06-24 23:31:02 +020039
Zesstra715ec202025-07-09 22:18:31 +020040SEE ALSO
MG Mud User88f12472016-06-24 23:31:02 +020041 clear_bit(E), set_bit(E), test_bit(E), next_bit(E), last_bit(E),
42 count_bits(E), or_bits(E), xor_bits(E), invert_bits(E), and_bits(E)