-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #30 #254
Open
demon36
wants to merge
8
commits into
jnr:master
Choose a base branch
from
demon36:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix #30 #254
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a88b8a6
fix #30
demon36 3fb7cec
implement WStringRef (mapping for wchar_t*), make set() work efficien…
demon36 b4ab181
bug fix for null terminated strings of allocated size less than maxLe…
demon36 d1658b9
utf-16/32 support for getCharSequence()
demon36 61ce834
revert unneeded length change, add WStringRef.reAllocate() & setMaxLe…
demon36 9d1d562
possible fixes for DirectMemoryIO.getString()
demon36 b796974
more compliant spacing
demon36 badc99e
make use of StringUtil.terminatorWidth() for better performance
demon36 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ | |
import java.nio.charset.CharsetEncoder; | ||
import java.nio.charset.CodingErrorAction; | ||
|
||
import jnr.ffi.provider.converters.StringUtil; | ||
|
||
/** | ||
* | ||
*/ | ||
|
@@ -64,7 +66,8 @@ public static CharSequence getCharSequence(ByteBuffer buf, Charset charset) { | |
final ByteBuffer buffer = buf.slice(); | ||
// Find the NUL terminator and limit to that, so the | ||
// StringBuffer/StringBuilder does not have superfluous NUL chars | ||
int end = indexOf(buffer, (byte) 0); | ||
final byte[] nullCharBytes = new byte[StringUtil.terminatorWidth(charset)]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we can cache the three known lengths and not reallocate this byte[] every time? |
||
int end = indexOf(buffer, nullCharBytes) - nullCharBytes.length; | ||
if (end < 0) { | ||
end = buffer.limit(); | ||
} | ||
|
@@ -141,6 +144,47 @@ public static int indexOf(ByteBuffer buf, byte value) { | |
return -1; | ||
} | ||
|
||
public static int indexOf(ByteBuffer buf, byte[] value) { | ||
int matchingBytesCount = 0; | ||
int offset = 0; | ||
if (buf.hasArray()) { | ||
byte[] array = buf.array(); | ||
int begin = buf.arrayOffset() + buf.position(); | ||
int end = buf.arrayOffset() + buf.limit(); | ||
while(offset < end && offset > -1) { | ||
if(array[begin + offset] == value[matchingBytesCount]) { | ||
matchingBytesCount++; | ||
offset++; | ||
} else { | ||
matchingBytesCount = 0; | ||
offset += value.length - (offset%value.length);//jump to start of next character | ||
continue; | ||
} | ||
|
||
if(matchingBytesCount == value.length) { | ||
return offset; | ||
} | ||
} | ||
} else { | ||
int begin = buf.position(); | ||
while(offset < buf.limit()) { | ||
if(buf.get(begin + offset) == value[matchingBytesCount]) { | ||
matchingBytesCount++; | ||
offset++; | ||
} else { | ||
matchingBytesCount = 0; | ||
offset += value.length - (offset%value.length);//jump to start of next character | ||
continue; | ||
} | ||
|
||
if(matchingBytesCount == value.length) { | ||
return offset; | ||
} | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
public static int indexOf(ByteBuffer buf, int offset, byte value) { | ||
if (buf.hasArray()) { | ||
byte[] array = buf.array(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting throughout should match the rest of the code, which is intended to match typical Java coding conventions:
if
andwhile
and their parenthesized conditionals+
and%
It's nitpicky but if we don't maintain consistent code formatting then we end up with future commits and PRs that have lots of unrelated changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, will take care of that