mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-09 13:10:17 +00:00
Add a polyfill to isascii(c)
This commit is contained in:
parent
bcf51c4535
commit
02a30130b2
3
include/pocketpy/common/isascii.h
Normal file
3
include/pocketpy/common/isascii.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define pkpy_isascii(c) ((unsigned)(c) < 0x80)
|
||||||
@ -1,5 +1,6 @@
|
|||||||
#include "pocketpy/common/str.h"
|
#include "pocketpy/common/str.h"
|
||||||
#include "pocketpy/common/utils.h"
|
#include "pocketpy/common/utils.h"
|
||||||
|
#include "pocketpy/common/isascii.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -24,7 +25,7 @@ void pkpy_Str__ctor(pkpy_Str *self, const char *data){
|
|||||||
|
|
||||||
static void pkpy_Str__check_ascii(pkpy_Str *self, char *p) {
|
static void pkpy_Str__check_ascii(pkpy_Str *self, char *p) {
|
||||||
for(int i = 0; i < self->size; i++){
|
for(int i = 0; i < self->size; i++){
|
||||||
if(!isascii(p[i])){
|
if(!pkpy_isascii(p[i])){
|
||||||
self->is_ascii = false;
|
self->is_ascii = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "pocketpy/common/str.hpp"
|
#include "pocketpy/common/str.hpp"
|
||||||
#include "pocketpy/common/gil.hpp"
|
#include "pocketpy/common/gil.hpp"
|
||||||
|
#include "pocketpy/common/isascii.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
@ -15,7 +16,7 @@ Str::Str(pair<char*, int> detached) {
|
|||||||
this->is_sso = false;
|
this->is_sso = false;
|
||||||
this->_ptr = detached.first;
|
this->_ptr = detached.first;
|
||||||
for(int i = 0; i < size; i++) {
|
for(int i = 0; i < size; i++) {
|
||||||
if(!isascii(_ptr[i])) {
|
if(!pkpy_isascii(_ptr[i])) {
|
||||||
is_ascii = false;
|
is_ascii = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user