Add a polyfill to isascii(c)

This commit is contained in:
方而静 2024-06-12 11:52:15 +08:00
parent bcf51c4535
commit 02a30130b2
3 changed files with 7 additions and 2 deletions

View File

@ -0,0 +1,3 @@
#pragma once
#define pkpy_isascii(c) ((unsigned)(c) < 0x80)

View File

@ -1,5 +1,6 @@
#include "pocketpy/common/str.h"
#include "pocketpy/common/utils.h"
#include "pocketpy/common/isascii.h"
#include <assert.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) {
for(int i = 0; i < self->size; i++){
if(!isascii(p[i])){
if(!pkpy_isascii(p[i])){
self->is_ascii = false;
break;
}

View File

@ -1,5 +1,6 @@
#include "pocketpy/common/str.hpp"
#include "pocketpy/common/gil.hpp"
#include "pocketpy/common/isascii.h"
#include <cassert>
#include <ostream>
@ -15,7 +16,7 @@ Str::Str(pair<char*, int> detached) {
this->is_sso = false;
this->_ptr = detached.first;
for(int i = 0; i < size; i++) {
if(!isascii(_ptr[i])) {
if(!pkpy_isascii(_ptr[i])) {
is_ascii = false;
break;
}